How to access a COM object from .NET

R

Robert Rotstein

If I have accessed a COM object in this manner:

Type MyType = Type.GetTypeFromProgID("someCOMobject");
Object ThisObj = Activator.CreateInstance(MyType);
object returnedItems = MyType.InvokeMember("someFunction",
System.Reflection.BindingFlags.InvokeMethod, null, ThisObj, null);

and I happen to know that returnedItems is a
Microsoft.VisualBasic.Collection object, then what is the correct way to
access the individual items in that collection? Doing

foreach (object item in (Collection) returnedItems)

causes an System.InvalidCastException exception.
 

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

Top