Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve the Interface ID of a COM class so that it can be passed to CoCreateInstance?
    primarykey
    data
    text
    <p>I want to programaticly retrieve the Interface ID for any class so that I can pass it to CoCreateInstance. Any help is very much appreciated!!</p> <p><B>See "How Do I Get This" below:</B></p> <pre><code>HRESULT hResult; CLSID ClassID; void *pInterface; if(!(hResult = SUCCEEDED(CoInitialize(NULL)))) { return 1; } if(S_OK == CLSIDFromProgID(OLESTR("Scripting.FileSystemObject"), &amp;ClassID)) { hResult = CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER, &lt;&lt;How Do I Get This?&gt;&gt;, (LPVOID *)&amp;pInterface); } CoUninitialize(); </code></pre> <p><b>EDIT: Thanks for all of the help, seems to work perfectly now! :</b></p> <pre><code>HRESULT hResult; CLSID ClassID; IClassFactory *pClf; void *pVdb; if(!(hResult = SUCCEEDED(CoInitialize(NULL)))) { return 1; } if(SUCCEEDED(CLSIDFromProgID(OLESTR("Scripting.FileSystemObject"), &amp;ClassID)) { IDispatch *pDispatch; if(SUCCEEDED(CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&amp;pDispatch)) { OLECHAR *sMember = L"FileExists"; DISPID idFileExists; if(SUCCEEDED(pDispatch-&gt;GetIDsOfNames( IID_NULL, &amp;sMember, 1, LOCALE_SYSTEM_DEFAULT, &amp;idFileExists)) { unsigned int puArgErr = 0; VARIANT VarResult; EXCEPINFO pExcepInfo; VariantInit(&amp;VarResult); VariantInit(&amp;pExcepInfo); DISPPARAMS pParams; memset(&amp;pParams, 0, sizeof(DISPPARAMS)); pParams.cArgs = 1; VARIANT Arguments[1]; VariantInit(&amp;Arguments[0]); pParams.rgvarg = Arguments; pParams.cNamedArgs = 0; pParams.rgvarg[0].vt = VT_BSTR; pParams.rgvarg[0].bstrVal = SysAllocString(L"C:\\Test.txt"); hResult = pDispatch-&gt;Invoke( idFileExists, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &amp;pParams, &amp;VarResult, &amp;pExcepInfo, &amp;puArgErr ); SysFreeString(pParams.rgvarg[0].bstrVal); printf("File Exists? %d\n", abs(VarResult.boolVal)); } pDispatch-&gt;Release(); } } CoUninitialize(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload