PC Review


Reply
Thread Tools Rate Thread

How to access a COM object from .NET

 
 
Robert Rotstein
Guest
Posts: n/a
 
      20th Sep 2005
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.
 
Reply With Quote
 
 
 
 
Ollie Riches
Guest
Posts: n/a
 
      21st Sep 2005
If you have a COM object (i.e. you have a dll that contains COM components)
why not create an interop assembly.

Check the following out:

http://msdn.microsoft.com/library/de...priinterop.asp

HTH

Ollie Riches

"Robert Rotstein" <(E-Mail Removed)> wrote in message
news:lG_Xe.8427$T55.3556@trndny06...
> 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.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Name does not follow Microsoft Access object-naming rules clk Microsoft Access VBA Modules 3 20th Aug 2010 03:17 PM
object name doesn't follow microsoft access object naming rules Chuck W Microsoft Access 3 11th Dec 2009 03:00 PM
To store object and access by key(string), what collection object is the best performance one? Thanks. david Microsoft C# .NET 1 12th Dec 2003 03:53 AM
Access 2000 - Insert OLE object programatically into a forms OLE object field jon Microsoft Access Macros 0 15th Sep 2003 08:13 AM
Access 2000 - Insert OLE object programatically into a forms OLE object field jon Microsoft Access VBA Modules 0 15th Sep 2003 07:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 PM.