I want to programaticly retreive the Interface ID for any or any class so that I can pass it to CoCreateInstance. Any help is very much so appreciated!!
See "How Do I Get This" below:
HRESULT hResult;
CLSID ClassID;
void *pInterface;
if(!(hResult = SUCCEEDED(CoInitialize(NULL))))
{
return 1;
}
if(S_OK == CLSIDFromProgID(OLESTR("Scripting.FileSystemObject"), &ClassID))
{
hResult = CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER,
<<How Do I Get This?>>, (LPVOID *)&pInterface);
}
CoUninitialize();
EDIT, Thanks for all of the help, Seems to work perfectly now! :
HRESULT hResult;
CLSID ClassID;
IClassFactory *pClf;
void *pVdb;
if(!(hResult = SUCCEEDED(CoInitialize(NULL))))
{
return 1;
}
if(SUCCEEDED(CLSIDFromProgID(OLESTR("Scripting.FileSystemObject"), &ClassID))
{
IDispatch *pDispatch;
if(SUCCEEDED(CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER,
IID_IDispatch, (void **)&pDispatch))
{
OLECHAR *sMember = L"FileExists";
DISPID idFileExists;
if(SUCCEEDED(pDispatch->GetIDsOfNames(
IID_NULL, &sMember, 1, LOCALE_SYSTEM_DEFAULT, &idFileExists))
{
unsigned int puArgErr = 0;
VARIANT VarResult;
EXCEPINFO pExcepInfo;
VariantInit(&VarResult);
VariantInit(&pExcepInfo);
DISPPARAMS pParams;
memset(&pParams, 0, sizeof(DISPPARAMS));
pParams.cArgs = 1;
VARIANT Arguments[1];
VariantInit(&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->Invoke(
idFileExists,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&pParams,
&VarResult,
&pExcepInfo,
&puArgErr
);
SysFreeString(pParams.rgvarg[0].bstrVal);
printf("File Exists? %d\n", abs(VarResult.boolVal));
}
pDispatch->Release();
}
}
CoUninitialize();