Similar Threads:
1.Problem with casting same COMImport interface from 2 different assemblies
A class in assembly A implements a COM interface as follows :
[ComImport, Guid("CEF04FDF-FE72-11d2-87A5-00C04F6837CF"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMyInterface
{
[PreserveSig]
int MyMethod();
}
class MyClass : IMyInterface
{
int MyMethod()
{
...
}
}
This interface is exposed to the unmanaged world via COM Interop.
Now, assembly B also defines IMyInterface and gets this interface from the
unmanaged world as follows :
IntPtr unk = GetMyInterface(); // Gets IMyInterface from unmanaged world
object obj = Marshal.GetObjectFromIUnkown(unk); // its really the class
MyClass from assembly A above
IMyInterface myIntf = obj as IMyInterface; // this cast does not work and
returns null becuase of separate declarations of IMyInterface in the two
assemblies !
How to get this scenario to work? One would think that .Net would recognize
that both the interfaces are the same ( based on the ComImport and Guid
attributes) and allow the cast, but it doesnt allow the cast.
It is not possible for me to use a shared assembly and put the declaration
of IMyInterface in that assembly.
So how can I solve this problem?
Thanks
Bob
2.Casting problem : COMImport interfaces in different assemblies
A class in assembly A implements a COM interface as follows :
[ComImport, Guid("CEF04FDF-FE72-11d2-87A5-00C04F6837CF"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMyInterface
{
[PreserveSig]
int MyMethod();
}
class MyClass : IMyInterface
{
int MyMethod()
{
...
}
}
This interface is exposed to the unmanaged world via COM Interop.
Now, assembly B also defines IMyInterface and gets this interface from the
unmanaged world as follows :
IntPtr unk = GetMyInterface(); // Gets IMyInterface from unmanaged world
object obj = Marshal.GetObjectFromIUnkown(unk); // its really the class
MyClass from assembly A above
IMyInterface myIntf = obj as IMyInterface; // this cast does not work and
returns null becuase of separate declarations of IMyInterface in the two
assemblies !
How to get this scenario to work? One would think that .Net would recognize
that both the interfaces are the same ( based on the ComImport and Guid
attributes) and allow the cast, but it doesnt allow the cast.
It is not possible for me to use a shared assembly and put the declaration
of IMyInterface in that assembly.
So how can I solve this problem?
Thanks
Bob
3.COM interface requires Integer in VB, even though INT_PTR is defined in COM interface
4.COM interface requires Integer in VB, even though INT_PTR is defined in COM interface
Hi,
I have a small problem. I have defined some interfaces in a COM dll,
and have defined some parameters in these interfaces as INT_PTR. I
thought that when I import the COM dll in Visual Basic.NET that I can
use IntPtr as the type for these parameters, but the intellisense
shows me that the parameters in the interfaces have been changed to
Integer instead of the VB type IntPtr.
So, now I need to cast to Int32. I would also like to compile this
code for x64, wherease I need to cast it to Int64. Is this normal
behavior and do I need to distinguish between x86 and x64 mode when
passing arguments to a COM interface that has INT_PTR as one of its
parameters, or is there another trick to have the interfaces become
compatible with the Visual Basic IntPtr type, regardless of x86 or
x64?
Also, what happens with "Option Strict Off"? I prefer not to use this
though.
Thanks in advance.
5.Passing a COM interface through a COM interface
6. Explicity interface visibility and Namespace Question
7. interface, implementation, and visibility
8. Expose a .NET interface to COM as an interface