Unfortunately there is a bug in GCHandle implementation on CF. IF you pin an
array you will get a pointer to a control structure instead of array data.
In particular for simple 1-dim arrays it will be address of array[-1]
holding numelements. To get a pointer to a real address it will need to be
incremented by 4.
"Daniel Petersson" <(E-Mail Removed)> wrote in message
news:268FBA49-44CE-4A19-B030-(E-Mail Removed)...
> To get the adress of an object for interop you use the IntPtr type
together
> with GCHandle.
>
> // an array of bytes
> byte[] bytes = new byte[]{ 1,2,3,4,5 };
>
> // pin array during interop operation and to get the address
> GCHandle pinnedArray = GCHandle.Alloc( bytes, GCHandleType.Pinned );
>
> // do funky interop call
> Win32.NativeCallThatNeedAdressOfArray( pinnedArray.AddrOfPinnedObject );
>
> // free the handle
> pinnedArray.Free();
|