Interop gurus: Is it possible to determine the type of an unknown COM object?

P

Philip Daniels

I am doing some work with a client API via COM interop. I have
reached the situation where after this call to their API:

object someObj = con.Peek(1);

"someObj" contains some type of COM object (shows type as
System.__COMObject).

I have no idea what someObj is, but it is likely to be some sort of
wrapper around an image : con.Peek(1) is ultimately retrieving a
bitmap from an IMAGE column in SQL server. I really can't be sure
though. I've tried casting someObj to all the types they expose in
their library and it fails on each one. (It's MBS Dynamics AX in case
you're interested).

Is it possible to figure out what someObj is and get the image data
out? Something using interop or reflection perhaps.

Any help much appreciated at this stage....
 
O

Ollie Riches

a bit rusty but here goes,

You could look up the interface using something like 'oleview.exe' - this
interogrates the registry and displays information about COM components.

If you want to do this programmatically - All COM interfaces derive from
IUknown and possibly IDispatch, If you query interface for the IDispatch
interface and recieve a valid interface back then you can use the
'GetTypeInfo' method to the info you want - this is only possible if the COM
object has support for OLE Automation (IDispatch). You will of course have
to add the IDispatch definition to yuor interop code.

HTH

Ollie Riches
 
M

me

a bit rusty but here goes,

You could look up the interface using something like 'oleview.exe' - this
interogrates the registry and displays information about COM components.

Ok I found that tool. It looks like .Net has imported everything
exposed in the DLL perfectly.
If you want to do this programmatically - All COM interfaces derive from
IUknown and possibly IDispatch, If you query interface for the IDispatch
interface and recieve a valid interface back then you can use the

Ollie, an example would really help...this works, but where do I go
from here?

IntPtr idesp = Marshal.GetIDispatchForObject(someObj);
 

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