C
Christopher Fairbairn
Hi,
I am currently working on some COM interop code within a .NET CF 2.0
application to hook into a third part COM library. In part this is a port of
some desktop code that currently works. I am having difficulty calling a
method implemented via an IDispatch based interface.
My native COM object has a method that returns a reference to another
IDispatch based object. I want my C# code to call a method via this
IDispatch based reference, knowing only the method's name.
The method within the COM object is declared in the C# wrapper class as
follows:
[ComImport()]
[Guid(".....")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface ISomeInterface
{
....
void GetManager([Out,MarshalAs(UnmanagedType.IDispatch)]out object
dispatch);
....
}
The code I have tried (and that works correctly on the desktop) is as
follows:
public void CallMethod(string method)
{
// Call the native COM object to obtain a
// reference to another IDispatch based object
object dispatch = null;
myComObject.GetManager(out dispatch);
// Call the desired method on this object
// The method accepts no parameters
Type t = dispatch.GetType();
t.InvokeMember(method, BindingFlags.InvokeMethod, null, dispatch, null);
}
The problem I am getting on the .NET Compact Framework is the call to
Type.InvokeMember is throwing a NotSupportedException, while on the desktop
this code looks up the required method via the IDispatch interface and
correctly invokes it.
The API I am attempting to access dynamically creates the contents of this
IDispatch based interface, meaning I can't use the delcarative approach to
wrap up an IDispatch based interface (using C#'s [DispId(1)] attributes
etc), since at compile time I do not know the names or dispatch ids for the
methods the COM object contains.
Is this NotSupportedException showing something wrong with my code, or is
this type of COM Interop not support within the .NET CF?
Thanks,
Christopher Fairbairn
I am currently working on some COM interop code within a .NET CF 2.0
application to hook into a third part COM library. In part this is a port of
some desktop code that currently works. I am having difficulty calling a
method implemented via an IDispatch based interface.
My native COM object has a method that returns a reference to another
IDispatch based object. I want my C# code to call a method via this
IDispatch based reference, knowing only the method's name.
The method within the COM object is declared in the C# wrapper class as
follows:
[ComImport()]
[Guid(".....")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface ISomeInterface
{
....
void GetManager([Out,MarshalAs(UnmanagedType.IDispatch)]out object
dispatch);
....
}
The code I have tried (and that works correctly on the desktop) is as
follows:
public void CallMethod(string method)
{
// Call the native COM object to obtain a
// reference to another IDispatch based object
object dispatch = null;
myComObject.GetManager(out dispatch);
// Call the desired method on this object
// The method accepts no parameters
Type t = dispatch.GetType();
t.InvokeMember(method, BindingFlags.InvokeMethod, null, dispatch, null);
}
The problem I am getting on the .NET Compact Framework is the call to
Type.InvokeMember is throwing a NotSupportedException, while on the desktop
this code looks up the required method via the IDispatch interface and
correctly invokes it.
The API I am attempting to access dynamically creates the contents of this
IDispatch based interface, meaning I can't use the delcarative approach to
wrap up an IDispatch based interface (using C#'s [DispId(1)] attributes
etc), since at compile time I do not know the names or dispatch ids for the
methods the COM object contains.
Is this NotSupportedException showing something wrong with my code, or is
this type of COM Interop not support within the .NET CF?
Thanks,
Christopher Fairbairn