You can use
CoLoadLibrary()
to load the dll and obtain a reference to it with the following code; just add the path to your dll to the first parameter. Also change references to
CLSID_CGeneric
and
IID_IGeneric
to your own GUID references.
Note that you should
always check the return code from
CoCreateInstance()
before trying to use the pointer.
if (hr == REGDB_E_CLASSNOTREG)
{
HINSTANCE hInstance = CoLoadLibrary([path to your DLL], FALSE);
if (hInstance != NULL)
{
typedef HRESULT (__stdcall *pDllGetClassObject)(REFCLSID rclsid, REFIID riid, PVOID* ppv);
pDllGetClassObject GetClassObject = (pDllGetClassObject)GetProcAddress(hInstance, "DllGetClassObject");
if (GetClassObject != NULL)
{
IClassFactory* pIFactory;
hr = GetClassObject(CLSID_CGeneric, IID_IClassFactory, (PVOID*)&pIFactory);
if (SUCCEEDED(hr))
{
hr = pIFactory->CreateInstance(NULL, IID_IGeneric, (PVOID*)&pGeneric);
pIFactory->Release();
}
}
}
}
if (SUCCEEDED(hr))
{
}