Pointer to a COM object when the application does not return it

I use a third-party application and make a call to instantiate the COM object my . This call succeeds, but the function in 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, there is some pseudo code here:

// This function has no return value! ThirdPartyApp.CreateObject("MyObject"); 
+4
source share
2 answers

When your object is created, force it to store the link to itself in a global variable or in some other place of joint storage. Then export the function from your COM DLL that will be read from this location so that you can call it and get a link to the previously created object.

This shared link should not increase the object's reference count, otherwise it will never be destroyed. When your object is destroyed, make sure you clear this shared link.

If you can have multiple instances of this object in the same process, you may need to manage the list, not just one global variable.

+2
source
  • Save the return value HRESULT (is it C ++?), This can give the key.
  • Sometimes there are difficult problems with sorting / creating if you call the factory -type object that exists in another apartment.
0
source

All Articles