How do I compare 2 objects which reference COM objects?

  • Thread starter Thread starter Uzi
  • Start date Start date
U

Uzi

Hi,
I have 2 references to COM objects (through interop). How do I compare
the tow to know if they are pointing to the same COM object?
The Object.Equals doesn't work in this case...
Thanks!
Uzi
 
You should be able to QueryInterface for IUnknown and compare the pointers.
 
Uzi said:
Hi,
I have 2 references to COM objects (through interop). How do I compare
the tow to know if they are pointing to the same COM object?
The Object.Equals doesn't work in this case...
Thanks!
Uzi

IntPtr IUnkn1 = Marshal.GetIUnknownForObject(o1);
IntPtr IUnkn2 = Marshal.GetIUnknownForObject(o2);
if (IUnkn1 == IUnkn2)
// same object
else
....


Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top