[Mono-dev] When passing managed array of COM object references (Marshaled as UnmanagedType.LPArray) to native Code, expected native COM ptrs are invalid.

Ivan N. Zlatev contact at i-nz.net
Sat Aug 16 06:46:21 EDT 2008


On Fri, Aug 15, 2008 at 2:43 AM, Tom Hindle <tom_hindle at sil.org> wrote:
>
> Hi,
>
> 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.

If it works on MS.NET and not on Mono then it's a bug and as such it
should be filed with a small self-contained test case. For information
on how to file bugs check: http://mono-project.com/Bugs .

>
> 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:
>
> [MethodImpl(MethodImplOptions.InternalCall,MethodCodeType=MethodCodeType.Runtime)]
> public virtual extern void PassComArray(
> int length,
> [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0]
> INativeCreatedObject[] a);
>
> 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
> doesn't work.
>
> IE:
>
> Test t = new Test(); // Create Com object Test
> INativeCreatedObject i;
> 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[10];
> array[0] = 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.
>
> IE:
>                                MethodImpl(MethodImplOptions.InternalCall,
> MethodCodeType=MethodCodeType.Runtime)]
> public virtual extern void
> PassIntArray([MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)]
>  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
> Assembler :(
>
> 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.
> Tom
>
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



--
Kind Regards,
Ivan N. Zlatev


More information about the Mono-devel-list mailing list