Re: converting double pointer in C#

From: Mattias Sjögren (mattias.dont.want.spam_at_mvps.org)
Date: 03/26/04


Date: Fri, 26 Mar 2004 21:35:39 +0100

John,

I'd do it like this

[DllImport("kernel32.dll", EntryPoint="RtlMoveMemory")]
static extern void CopyMemory(IntPtr dest, IntPtr[] src, int cb);

IntPtr[] ptrs = new IntPtr[10];
for ( int i = 0; i < ptrs.Length; i++ )
  ptrs[i] = Marshal.AllocHGlobal( 256 );
_list.test_list = Marshal.AllocHGlobal(10 * IntPtr.Size);
CopyMemory(_list.test_list, ptrs, 10 * IntPtr.Size);

And don't forget to free the memory when you're done.

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