JJ
2022-04-20 19:50:00 UTC
I'm trying to use a third party COM object in a DLL when the DLL is being
loaded (i.e. at DLL_PROCESS_ATTACH stage).
The COM object is instantiated using CoGetObject() like below, but it hangs.
For the sake of reproducing the problem in any system, the WMI service
object is used as an example.
CoInitializeEx(NULL, COINIT_MULTITHREADED); //returns zero. already checked.
CoGetObject(L"winmgmts:", NULL, IID_IDispatch, &pObj); //it hangs
//code execution never reached here
The code works fine if it's executed from an exported DLL function and
called by the host process, after LoadLibrary() returns.
What's went wrong? Is there a solution? Or is it that, CoGetObject() can not
be used during DLL_PROCESS_ATTACH?
Note: WMI has `WbemScripting.SWbemLocator` alternative class name for use
with CoCreateInstance(). The third party COM object I'm actually using, does
not have any alternative class name which is usable with CoCreateInstance().
So, I can not use CoCreateInstance().
loaded (i.e. at DLL_PROCESS_ATTACH stage).
The COM object is instantiated using CoGetObject() like below, but it hangs.
For the sake of reproducing the problem in any system, the WMI service
object is used as an example.
CoInitializeEx(NULL, COINIT_MULTITHREADED); //returns zero. already checked.
CoGetObject(L"winmgmts:", NULL, IID_IDispatch, &pObj); //it hangs
//code execution never reached here
The code works fine if it's executed from an exported DLL function and
called by the host process, after LoadLibrary() returns.
What's went wrong? Is there a solution? Or is it that, CoGetObject() can not
be used during DLL_PROCESS_ATTACH?
Note: WMI has `WbemScripting.SWbemLocator` alternative class name for use
with CoCreateInstance(). The third party COM object I'm actually using, does
not have any alternative class name which is usable with CoCreateInstance().
So, I can not use CoCreateInstance().