CComPtr Error CoCreateInstance ()

I have a COM .dll

registered successfully with regsvr32

but somehow CoCreateInstance()

fails to create one of its interfaces. Is there a free tool that can determine the cause of the crash?

0


source to share


2 answers


First of all, check the return value of the call to CoCreateInstance (). Second, you can use a tool like Regmon or Process Monitor to find out what registry errors are failing. This way, you can quickly determine what exactly was not registered as you expected.



+2


source


If your com dll is implemented in C ++ and has debug information, you can also try debugging with MSVC to go to CoCreateInstance.

I assume you missed binding your class to one of the interfaces. I've done this several times by mistake. If you are using ATL, you need to make sure that your implementing class is derived from the interface, and you also add COM_INTERFACE_ENTRY(I____)

for your interface in COM_MAP:

BEGIN_COM_MAP(CFileHelper)
    COM_INTERFACE_ENTRY(IFileHelper)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IStream)
    COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

      



Or maybe the GUID is different between the IDL file and the one in the C ++ executable. MSVC6 has an annoying error if the wizard cannot create a new class due to file permissions (for example, some of the files it wants to change are read-only), but it has already added the GUID to the IDL file and you fix the permissions files and go to repeat this step, there will be an inconsistency in the GUID and it's a pain to catch this. In an ideal world, GUID definitions would be in ONLY one file, and then you wouldn't have to worry about that.

If this is not the case, weird errors sometimes occur with regards to marshaling and apartments, but they only appear if you have multiple threads and send interface pointers along thread or interface boundaries.

0


source







All Articles