Re: Marshalling Array In/Out C++ COM Control
From: KidO (KidO_at_discussions.microsoft.com)
Date: 11/17/04
- Next message: wannensn: "Remoting/Interop with Interfaces"
- Previous message: Jeff Gaines: "Re: null reference exception on DLL call in C#"
- In reply to: Mattias Sjögren: "Re: Marshalling Array In/Out C++ COM Control"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Nov 2004 06:54:03 -0800
Mattias,
Thank you for your response, and I hope you may still be watching this thread.
I have previously tried the code in the link you recommended, and have
created a number of variations, including fixing a pointer to the array,
using Marshal.AllocCoTaskMem to allocate memory for the array, etc.
When using the method described in the link
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconeditinginteropassembly.asp
the method call fails and a System.Runtime.InteropServices.COMException
occurs in mscorlib.dll, with the Additional information: Type Mismatch.
When the method of the OCX returns succesfully (no error), only the first
value in the array is passed back. Even with the untouched interop assembly
generated by aximp, this is the case, although I can not use an array larger
than 4 items.
Using OLEView, the the method looks like:
VARIANT_BOOL DetectCode(long* codeArray, short* arraySize)
The orginal IL of the interop assembly generated by aximp looks like:
instance bool DetectCode(int32& codeArray, int16& arraySize) runtime managed
preservesig internalcall
When the method is called, codeArray is intialized, and contains all 0's.
arraySize is the number of elements in codeArray. If the method call is
succesful, it returns true, and codeArray contains a number of values up to
the size set in arraysize, and arraySize is the actual (useful) number of
elements in the array.
Thanks in advance for your help.
John
"Mattias Sjögren" wrote:
>
> You don't clearly state what the problem is, but I assume it's the
> fact that the array parameter appears as a single ref parameter
> instead of an array in managed code. If so, tyou can find the solution
> at
>
> http://msdn.microsoft.com/library/en-us/cpguide/html/cpconeditinginteropassembly.asp
>
> in the exction "Conformant C-Style Arrays". Just make sure you specify
> the [out] attribute as well since you're working with output
> parameters.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
>
- Next message: wannensn: "Remoting/Interop with Interfaces"
- Previous message: Jeff Gaines: "Re: null reference exception on DLL call in C#"
- In reply to: Mattias Sjögren: "Re: Marshalling Array In/Out C++ COM Control"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|