[Mono-dev] When passing managed array of COM object references (Marshaled as UnmanagedType.LPArray) to native Code, expected native COM ptrs are invalid.
tom_hindle at sil.org
Thu Aug 14 20:43:31 EDT 2008
When passing managed array of COM object references (Marshaled as
UnmanagedType.LPArray) to native Code, expected native COM ptrs are
invalid. This same technique works when running on MS .Net.
1. I'm running on Linux (Hardy), using mono build from svn.
2. I have created 2 C++ COM objects using libCom.
3. I have created a c# Interop to call/create these COM objects.
relevant line in Interop is:
public virtual extern void PassComArray(
4. I create an instance of the COM object in c#
I use that to return a Naively created COM object to c#.
I can use this COM object in c#.
However passing this COM object ref as an array back to native
Test t = new Test(); // Create Com object Test
t.CreateNativeObject(out i); // return another Com object created
naively. // prints address as 0x83cbd50
i.DoSomething(); // Works fine.
// Create managed array
INativeCreatedObject array = new INativeCreatedObject;
array = i;
t.PassComArray(1, array); // address of array element 0 is 0x60d80 not
0x83cbd50 which means using the COM object ptr will crash.
5. This Marshaling technique works in mono when passing int's.
public virtual extern void
int length, int a);
6. after gdb-ing mono I suspect the problem with the CIL that is
generated for the marshaling (is it called the Runtime Callable
Wrapper?) However I can't verify this as I can't program in any
I have a work around using a custom marshaler, but I would rather use
the same interops on both Windows and Linux.
Thanks in advance for any advice.
More information about the Mono-devel-list