COM objects from C#

Started by
0 comments, last by outRider 20 years, 7 months ago
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 -
Advertisement
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 -

This topic is closed to new replies.

Advertisement