Markus_Karg
April 24th, 1999, 05:11 AM
I am just a beginner in COM programming and wanted to start with a simple example: Adding a context menu handler to the WinNT4 explorer.
All just went good until now, and I don't know where I am wrong because hardly all of my code is copied from the SDK samples delivered with VC5.
The problem is: My DLL gets loaded and DllGetClassObject is called. My implementation of QueryInterface is called (the explorer asks for IID_ClassFactory which I expected). Now see the following code (from SDK examples):
extern "C" HRESULT __stdcall DllGetClassObject ( REFCLSID rclsid , REFIID riid , LPVOID * ppvObj )
{
HRESULT hRes = E_OUTOFMEMORY ;
* ppvObj = NULL ;
CMyClassFactory * pClassFactory = new CMyClassFactory ( /* rclsid */ ) ;
if ( pClassFactory != NULL )
{
hRes = E_UNEXPECTED ;
if ( riid == IID_IClassFactory )
{
hRes = pClassFactory -> QueryInterface ( riid , ppvObj ) ;
pClassFactory -> Release ( ) ;
}
}
return hRes ;
}
After finishing the call to DllGetClassObject, my debug log says that QueryInterface (and AddRef, which is called from inner QueryInterface) is done, even Release is done, which frees the newly created instance - all right I think, it's just what the SDK examples do.
But then, there is NEVER Initialize (IShellExtInit) NOR CreateInstance (IClassFactory) called!
When I do NOT call Release in the upper code, Initialize (IShellExtInit) is called, but CreateInstance (IClassFactory) is NEVER called but the is a GPF.
Where am I wrong?
From former times I know there is a bug in the SDK examples somewhere, but I can't remeber where!
Markus Karg
All just went good until now, and I don't know where I am wrong because hardly all of my code is copied from the SDK samples delivered with VC5.
The problem is: My DLL gets loaded and DllGetClassObject is called. My implementation of QueryInterface is called (the explorer asks for IID_ClassFactory which I expected). Now see the following code (from SDK examples):
extern "C" HRESULT __stdcall DllGetClassObject ( REFCLSID rclsid , REFIID riid , LPVOID * ppvObj )
{
HRESULT hRes = E_OUTOFMEMORY ;
* ppvObj = NULL ;
CMyClassFactory * pClassFactory = new CMyClassFactory ( /* rclsid */ ) ;
if ( pClassFactory != NULL )
{
hRes = E_UNEXPECTED ;
if ( riid == IID_IClassFactory )
{
hRes = pClassFactory -> QueryInterface ( riid , ppvObj ) ;
pClassFactory -> Release ( ) ;
}
}
return hRes ;
}
After finishing the call to DllGetClassObject, my debug log says that QueryInterface (and AddRef, which is called from inner QueryInterface) is done, even Release is done, which frees the newly created instance - all right I think, it's just what the SDK examples do.
But then, there is NEVER Initialize (IShellExtInit) NOR CreateInstance (IClassFactory) called!
When I do NOT call Release in the upper code, Initialize (IShellExtInit) is called, but CreateInstance (IClassFactory) is NEVER called but the is a GPF.
Where am I wrong?
From former times I know there is a bug in the SDK examples somewhere, but I can't remeber where!
Markus Karg