tags:

views:

61

answers:

2

I am using a third-party application, and making a call to create an instance of my COM object. This call is succeeding, however the function on the third-party application does not return a pointer to the created object (I have no idea why). Is there any way to get a pointer to my object?

To clarify, here's some pseudo-code:

// This function has no return value!
ThirdPartyApp.CreateObject("MyObject");
+2  A: 

When your object is created, make it store a reference to itself in a global variable or some other sort of shareable storage location. Then export a function from your COM DLL that will read from that location so you can call it and get a reference to the previously created object.

This shared reference should not increase the reference count of the object, or else it will never get destroyed. When your object gets destroyed, make sure you clear that shared reference.

If you can have more than one instance of this object in the same process, then you may need to manage a list instead of just a single global variable.

Rob Kennedy
A: 
  1. Store your return value HRESULT (is this C++?), it may yield a clue.
  2. Sometimes there are sneaky tricky marshalling/creation problems if you are calling a factory-type object which exists in another apartment.
Jason S