M
Marvin Landman
Hi,
I would like to expose some objects using COM to native code.
My problem is that IDispatch seems to require the class to be public to
work.
I have a class with an interface, both are internal.
[System.Runtime.InteropServices.ComDefaultInterface (typeof (IMyInterface))]
[System.Runtime.InteropServices.ClassInterface
(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible (true)]
internal class MyClass : IMyInterface
[System.Runtime.InteropServices.InterfaceType
(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsDual)]
internal interface IMyInterface
This succeeds:
System.Runtime.InteropServices.Marshal.GetComInterfaceForObject(myobjectoftypemyclass,
typeof(IMyInterface));
This results in InvalidCastException:
System.Runtime.InteropServices.Marshal.GetIDispatchForObject
(myobjectoftypemyclass);
This could work but the native side explicitly requests and IDispatch
interface so I get the exception (as a HResult) even if I pass the
result of GetComInterfaceForObject.
If I make MyClass public the problem is solved. But I would like to keep
MyClass internal and expose IMyInterface as its IDispatch interface.
Thank you.
Regards,
Marvin
I would like to expose some objects using COM to native code.
My problem is that IDispatch seems to require the class to be public to
work.
I have a class with an interface, both are internal.
[System.Runtime.InteropServices.ComDefaultInterface (typeof (IMyInterface))]
[System.Runtime.InteropServices.ClassInterface
(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible (true)]
internal class MyClass : IMyInterface
[System.Runtime.InteropServices.InterfaceType
(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsDual)]
internal interface IMyInterface
This succeeds:
System.Runtime.InteropServices.Marshal.GetComInterfaceForObject(myobjectoftypemyclass,
typeof(IMyInterface));
This results in InvalidCastException:
System.Runtime.InteropServices.Marshal.GetIDispatchForObject
(myobjectoftypemyclass);
This could work but the native side explicitly requests and IDispatch
interface so I get the exception (as a HResult) even if I pass the
result of GetComInterfaceForObject.
If I make MyClass public the problem is solved. But I would like to keep
MyClass internal and expose IMyInterface as its IDispatch interface.
Thank you.
Regards,
Marvin