15,471
社区成员
发帖
与我相关
我的任务
分享
HRESULT
CreateCOMObject(HMODULE hMod, // [in]
REFCLSID iidClass, // [in] CLSID of the COM object to create
REFIID iidInterface, // [in] GUID of the interface to get
LPVOID FAR* ppIface) // [in] on success, interface to the COM object is returned
{
HRESULT hr = S_OK;
HRESULT (WINAPI *pfnGetFactory)(REFCLSID, REFIID, void**);
*ppIface = NULL;
pfnGetFactory = (HRESULT (WINAPI *)(REFCLSID, REFIID, void**))GetProcAddress(hMod, "DllGetClassObject");
if ( ! pfnGetFactory)
return HRESULT_FROM_WIN32(GetLastError());
IClassFactory* pFactory = NULL;
hr = pfnGetFactory(iidClass, IID_IClassFactory, (void**)&pFactory);
if (SUCCEEDED(hr)) {
hr = pFactory->CreateInstance(NULL, iidInterface, (void**)ppIface);
pFactory->Release();
}
return hr;
}