This is a continuation of Registration of the implementation of the COM interface ; only now i have the actual code that needs debugging.
I have two COM objects, one of which implements IAudioSessionEvents and one that implements IClassFactory and creates the first object.
The following code registers these objects (according to my understanding of COM registration):
BOOL RegisterClassManually(WCHAR* szGuid, WCHAR* szDllPath)
{
WCHAR szKeyName[1024];
wsprintf(szKeyName, TEXT("Software\\Classes\\CLSID\\%s"), szGuid);
if(!RegisterKeyValue(HKEY_CURRENT_USER, szKeyName, NULL, TEXT(DESCRIPTION_CONST))) return false;
wsprintf(szKeyName, TEXT("Software\\Classes\\CLSID\\%s\\InprocServer32"), szGuid);
if(!RegisterKeyValue(HKEY_CURRENT_USER, szKeyName, NULL, szDllPath)) return false;
if(!RegisterKeyValue(HKEY_CURRENT_USER, szKeyName, TEXT("ThreadingModel"), TEXT("Apartment"))) return false;
return true;
}
STDAPI DllRegisterServer()
{
WCHAR* szGuid;
WCHAR szDllPath[512];
StringFromCLSID(CLSID_AudioEventsFactory, &szGuid);
if(g_dllModule == NULL) return SELFREG_E_CLASS;
GetModuleFileName(g_dllModule, szDllPath, 512);
if(!RegisterClassManually(szGuid, szDllPath)) return SELFREG_E_CLASS;
StringFromCLSID(CLSID_AudioEvents, &szGuid);
if(!RegisterClassManually(szGuid, szDllPath)) return SELFREG_E_CLASS;
return S_OK;
}
I missed RegisterKeyValue (...), its simple registry code, which I confirmed, works as intended.
This code is trying to use these COM objects:
IAudioSessionEvents* listener = NULL;
IClassFactory* factory = NULL;
hr = CoGetClassObject(CLSID_AudioEventsFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&factory);
if(hr != S_OK)
{
... Report Error ...
}
hr = factory->CreateInstance(NULL, __uuidof(IAudioSessionEvents), (void**)&listener);
Calling CoGetClassObject (...) returns hr = 0x80040111 (ClassFactory cannot provide the requested class).
Implementation of DllGetClassObject (for 1800 information indicating ommision):
STDAPI DllGetClassObject(const CLSID& clsid,
const IID& iid,
void** ppv)
{
if (clsid == __uuidof(IClassFactory))
{
AudioEventsFactory *pFact = new AudioEventsFactory;
if (pFact == NULL)
return E_OUTOFMEMORY;
else
{
return pFact->QueryInterface(iid , ppv);
}
}
return CLASS_E_CLASSNOTAVAILABLE;
}
? COM, , , . , .