
Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Thanks for the information.
I understood the part about the IUnknown:QueryInterface,
since I used this before in C++. What I didn't understand
was the part about the typelib. Do you suggest to iterate
over the list of all the interfaces exposed in the type
library, and try to cast to these interfaces?
I know that my COM component is also used from VB
scripting (because all the samples in the documentation
are VB script!) The samples don't care what interface the
returned object exposes, they just call a method
named "GetTextContents()" on the object. Apparently, this
is a valid method for all returned object types.
Is there a way to simulate this in C#.NET? Just look up
the method named "GetTextContents()" and then call the
method, without caring about interfaces? Is this
something I would use PInvoke() for? And is this related
to IDispatch()?
Regards, Beat Nideröst
>You could perhaps try to locate a typelib for the component, and then
>use the ITypeLib/ITypeInfo APIs to determine which interfaces the
[quoted text clipped - 4 lines]
>
>Mattias
Mattias Sj?gren - 29 Jul 2003 23:25 GMT
Beat,
>Do you suggest to iterate
>over the list of all the interfaces exposed in the type
>library, and try to cast to these interfaces?
Exactly, but it sounds like that isn't needed in this case.
>Is there a way to simulate this in C#.NET? Just look up
>the method named "GetTextContents()" and then call the
>method, without caring about interfaces? Is this
>something I would use PInvoke() for? And is this related
>to IDispatch()?
Yes you can do this in C# (though it's easier in VB.NET), and yes it's
related to IDispatch. Late bound COM calls are done with
Type.InvokeMember in C#, something like
object o = TheComObject;
object returnVal = o.GetType().InvokeMember(
"GetTextContents", BindingFlags.InvokeMethod, null, o,
new object[] {...any method arguments here...} );
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.