Error instantiating COM object

currently I'm struggling trying to use a COM dll on a simple system that I've made. Everything compiles successfully, but in runtime the CoCreateInstace is returning S_OK, but somehow my object pointer is returning NULL.

This interface pointer is created on my class header. The weirdest thing is that instantiating this same pointer type on the method stack results in a correct object, but subsequent calls to __hook turn on an access violation when trying to create a BASE com class.

Some other aspects that might be useful:

PS: As bonus question, why google doesn't return anything favorable related to COM? :)

Upvotes: 0

Views: 282

Answers (2)

Found the problem: The module attribute was defined on a static library, and that made the COM object go crazy; Moving it to the DLL source resolved the problem.

Upvotes: 0

Michael
Michael

Reputation: 55395

It sounds like a bug in the COM object's implementation of IUnknown::QueryInterface - not setting the output pointer but returning S_OK.

CoCreateInstance for an in-proc server is basically:

  • Load the DLL into memory
  • Call DllGetClassObject to get the class factory
  • Call IClassFactory::CreateInstance from the class factory which allocates a new object
  • Call IUnknown::QueryInterface on the new object to get the desired interface.

Returning NULL but S_OK at any step should result in a crash, except for the QI call at the end.

Upvotes: 2

Related Questions