Re: Marshalling Array In/Out C++ COM Control

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: KidO (KidO_at_discussions.microsoft.com)
Date: 11/17/04


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.
>



Relevant Pages

  • Dynamic array
    ... i wanted that it automatically calcule the size of the array, ... Dim anotherIteration As Boolean ... Dim arraySize As Integer ...
    (microsoft.public.excel.programming)
  • Re: Marshalling Array In/Out C++ COM Control
    ... I am having this exact problem. ... > using Marshal.AllocCoTaskMem to allocate memory for the array, ... > When the method is called, codeArray is intialized, and contains all 0's. ... > arraySize is the number of elements in codeArray. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: puzzle
    ... > the array appear exactly two times except one. ... Consider that if you choose a random number or the midpoint from the ... delete, delete// Changes arraySize ... Select the midpoint of the middle partition, or the last entry of the ...
    (comp.programming)
  • Re: need fastest way to write 2gig array to disk file
    ... You might consider using mmap on this array. ... size_t arraysize = sizeof*BIGSIZE; ... void* arrayaddr = mmap0, arraysize, PROT_READ|PROT_WRITE, ... // unmap memory and close file ...
    (comp.os.linux.development.apps)