Click here to Skip to main content
15,909,953 members
Home / Discussions / COM
   

COM

 
AnswerRe: How to create an ATL\COM dll object in a C++ Client Application? Pin
prasad_som30-Aug-06 23:33
prasad_som30-Aug-06 23:33 
AnswerRe: How to create an ATL\COM dll object in a C++ Client Application? Pin
satindar_kumar30-Aug-06 23:40
satindar_kumar30-Aug-06 23:40 
QuestionHow to run Dos Command in Dotnet witout opening Command Prompt Pin
Harshad Pednekar29-Aug-06 23:55
Harshad Pednekar29-Aug-06 23:55 
GeneralRe: How to run Dos Command in Dotnet witout opening Command Prompt Pin
prasad_som30-Aug-06 3:00
prasad_som30-Aug-06 3:00 
QuestionRe: How to run Dos Command in Dotnet witout opening Command Prompt Pin
Harshad Pednekar9-Sep-06 0:08
Harshad Pednekar9-Sep-06 0:08 
Questionerror LNK2001: unresolved external symbol _CLSID...... Pin
Rinu_Raj29-Aug-06 23:32
Rinu_Raj29-Aug-06 23:32 
AnswerRe: error LNK2001: unresolved external symbol _CLSID...... Pin
Steve S30-Aug-06 0:30
Steve S30-Aug-06 0:30 
QuestionMethod of WMI Class SystemRestore on Windows Vista doesn't work! Pin
dmitriu29-Aug-06 22:24
dmitriu29-Aug-06 22:24 
Hello!

I'm trying to turn on/off system restore on Windows Vista by
calling methods Enable/Disable of WMI Class SystemRestore.
My program works ok on Windows XP. But when I try to run
it on Windows Vista I don't have the desired result.
The ReturnValue of method ExecMethod equals to RPC_X_NULL_REF_POINTER
(A null reference pointer was passed to the stub).
Can anyone help me and tell what's wrong.
Here is the code of my program

<br />
<br />
    HRESULT hres;<br />
<br />
    hres =  CoInitializeEx(0, COINIT_MULTITHREADED); <br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Failed to initialize COM library. Error code = 0x" <br />
             << hex << hres << endl;<br />
        return 1;                  // Program has failed.<br />
    }<br />
<br />
    hres =  CoInitializeSecurity(<br />
        NULL, <br />
        -1,                          // COM negotiates service<br />
        NULL,                        // Authentication services<br />
        NULL,                        // Reserved<br />
        RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication <br />
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  <br />
        NULL,                        // Authentication info<br />
        EOAC_NONE,                   // Additional capabilities <br />
        NULL                         // Reserved<br />
        );<br />
<br />
                      <br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Failed to initialize security. Error code = 0x" <br />
             << hex << hres << endl;<br />
        CoUninitialize();<br />
        return 1;                      // Program has failed.<br />
    }<br />
   <br />
    IWbemLocator *pLoc = NULL;<br />
<br />
    hres = CoCreateInstance(<br />
        CLSID_WbemLocator,             <br />
        0, <br />
        CLSCTX_INPROC_SERVER, <br />
        IID_IWbemLocator, (LPVOID *) &pLoc);<br />
 <br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Failed to create IWbemLocator object. "<br />
             << "Err code = 0x"<br />
             << hex << hres << endl;<br />
        CoUninitialize();<br />
        return 1;                 // Program has failed.<br />
    }<br />
<br />
<br />
    IWbemServices *pSvc = NULL;<br />
	<br />
    hres = pLoc->ConnectServer(<br />
        _bstr_t(L"ROOT\\Default"), <br />
        NULL,<br />
        NULL, <br />
        0, <br />
        NULL, <br />
        0, <br />
        0, <br />
        &pSvc<br />
    );<br />
	    <br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Could not connect. Error code = 0x" <br />
             << hex << hres << endl;<br />
        pLoc->Release();     <br />
        CoUninitialize();<br />
        return 1;                // Program has failed.<br />
    }<br />
<br />
    cout << "Connected to ROOT\\Default WMI namespace" << endl;<br />
<br />
    hres = CoSetProxyBlanket(<br />
        pSvc,                        // Indicates the proxy to set<br />
        RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx <br />
        RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx <br />
        NULL,                        // Server principal name <br />
        RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx <br />
        RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx<br />
        NULL,                        // client identity<br />
        EOAC_NONE                    // proxy capabilities <br />
    );<br />
<br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Could not set proxy blanket. Error code = 0x" <br />
             << hex << hres << endl;<br />
        pSvc->Release();<br />
        pLoc->Release();     <br />
        CoUninitialize();<br />
        return 1;               // Program has failed.<br />
    }<br />
<br />
<br />
    BSTR MethodName = SysAllocString(L"Disable");<br />
    BSTR ClassName = SysAllocString(L"SystemRestore");<br />
<br />
    IWbemClassObject* pClass = NULL;<br />
    hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);<br />
<br />
    IWbemClassObject* pInParamsDefinition = NULL;<br />
    hres = pClass->GetMethod(MethodName, 0, <br />
        &pInParamsDefinition, NULL);<br />
<br />
    IWbemClassObject* pClassInstance = NULL;<br />
    hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);<br />
<br />
    VARIANT varCommand;<br />
    varCommand.vt = VT_BSTR;<br />
    varCommand.bstrVal = L"C:\\";<br />
<br />
    hres = pClassInstance->Put(L"Drive", 0,<br />
        &varCommand, 0);<br />
    wprintf(L"The command is: %s\n", V_BSTR(&varCommand));<br />
<br />
    // Execute Method<br />
    IWbemClassObject* pOutParams = NULL;<br />
    hres = pSvc->ExecMethod(ClassName, MethodName, 0,<br />
    NULL, pClassInstance, &pOutParams, NULL);<br />
<br />
    if (FAILED(hres))<br />
    {<br />
        cout << "Could not execute method. Error code = 0x" <br />
             << hex << hres << endl;<br />
        VariantClear(&varCommand);<br />
        SysFreeString(ClassName);<br />
        SysFreeString(MethodName);<br />
        pClass->Release();<br />
        pInParamsDefinition->Release();<br />
        pOutParams->Release();<br />
        pSvc->Release();<br />
        pLoc->Release();     <br />
        CoUninitialize();<br />
        return 1;               // Program has failed.<br />
    }<br />
<br />
 <br />
    VARIANT varReturnValue;<br />
    hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0, <br />
        &varReturnValue, NULL, 0);<br />
<br />
    cout << "Return Value: " << V_I4(&varReturnValue);<br />
<br />
<br />
    // Clean up<br />
    //--------------------------<br />
    VariantClear(&varCommand);<br />
    VariantClear(&varReturnValue);<br />
    SysFreeString(ClassName);<br />
    SysFreeString(MethodName);<br />
    pClass->Release();<br />
    pInParamsDefinition->Release();<br />
    pOutParams->Release();<br />
    pLoc->Release();<br />
    pSvc->Release();<br />
    CoUninitialize();<br />
<br />
    getchar();<br />
    return 0;<br />
<br />

QuestionAre user32.dll ,kernel32.dll... COM dlls? Pin
sawerr29-Aug-06 6:45
sawerr29-Aug-06 6:45 
AnswerRe: Are user32.dll ,kernel32.dll... COM dlls? Pin
Mike Dimmick29-Aug-06 6:52
Mike Dimmick29-Aug-06 6:52 
GeneralRe: Are user32.dll ,kernel32.dll... COM dlls? Pin
sawerr29-Aug-06 7:02
sawerr29-Aug-06 7:02 
GeneralRe: Are user32.dll ,kernel32.dll... COM dlls? Pin
Steve S29-Aug-06 21:35
Steve S29-Aug-06 21:35 
QuestionEmbedding an ActiveX control in another Pin
TClarke29-Aug-06 6:06
TClarke29-Aug-06 6:06 
AnswerRe: Embedding an ActiveX control in another Pin
Roger Stoltz30-Aug-06 23:33
Roger Stoltz30-Aug-06 23:33 
GeneralRe: Embedding an ActiveX control in another Pin
TClarke30-Aug-06 23:42
TClarke30-Aug-06 23:42 
GeneralRe: Embedding an ActiveX control in another Pin
TClarke31-Aug-06 1:05
TClarke31-Aug-06 1:05 
GeneralRe: Embedding an ActiveX control in another Pin
Roger Stoltz31-Aug-06 4:10
Roger Stoltz31-Aug-06 4:10 
Questionunregistering COM Pin
_tasleem29-Aug-06 3:05
_tasleem29-Aug-06 3:05 
AnswerRe: unregistering COM Pin
Steve S29-Aug-06 5:12
Steve S29-Aug-06 5:12 
QuestionPassing an Array of BSTR Pin
HakunaMatada28-Aug-06 20:51
HakunaMatada28-Aug-06 20:51 
AnswerRe: Passing an Array of BSTR Pin
Steve S29-Aug-06 2:39
Steve S29-Aug-06 2:39 
Questionnew vs CoCreateInstance Pin
_AnsHUMAN_ 28-Aug-06 0:10
_AnsHUMAN_ 28-Aug-06 0:10 
AnswerRe: new vs CoCreateInstance Pin
Steve S29-Aug-06 5:18
Steve S29-Aug-06 5:18 
Questionautomatic call Pin
_tasleem27-Aug-06 22:04
_tasleem27-Aug-06 22:04 
AnswerRe: automatic call Pin
prasad_som27-Aug-06 23:19
prasad_som27-Aug-06 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.