Archived

This topic is now archived and is closed to further replies.

outRider

COM objects from C#

Recommended Posts

Basically, I need to grab various COM objects from within C#. I''ve added a ref to what I need and what have you, but the sample code for UPnP on Microsoft''s site is only in C++, and doesn''t make sense. Where he/she calls pDevices->get__NewEnum(&pUnknown); I call System.Collections.IEnumerator Enum = Devices.GetEnumerator(); but after that things get a little awkward. IEnumerator doesn''t expose any sort of QueryInterface method... It has a GetType method and maybe a Type object can retrieve the IUnknown interface for QueryInterface, but who knows. Does anyone have any experience with COM in C#? ------------ - outRider -

Share this post


Link to post
Share on other sites
Well, if anyone is interested all I had to do was cast the IEnumerator.Current property to a specific type and if the object supported that interface the cast would succeed, else throw an exception. No messing with QueryInterface(). Also works for variants, just use the object type and cast to whatever.

------------
- outRider -

Share this post


Link to post
Share on other sites