How to load COM object in smart device project?

Posted by Daan on Stack Overflow See other posts from Stack Overflow or by Daan
Published on 2011-01-12T13:36:32Z Indexed on 2011/01/12 13:54 UTC
Read the original article Hit count: 282

I want to create a .NET CF application for Windows Mobile 5. In this application, I want to load a COM object based on the ProgID (or CLSID).

  1. How do I load this COM object in such a way that I can access its methods as if it were just another .NET object?
  2. In addition: how can I configure the projects / solutions in Visual Studio in such a way, that when I debug the application, I am sure that the COM object that is loaded is the one that is installed on the device, not one that may be accessible through the debugger?

I have tried adding the .ocx file as a Reference, but I get an error, and I am not sure about 'question 2'. I have also tried loading the COM object using

Type type = Type.GetTypeFromProgID("my.prog.id")
MyObject myObject = (MyObject)Activator.CreateInstance(type)

...but this results in an InvalidCastException on the second line.

© Stack Overflow or respective owner

Related posts about c#

Related posts about com