Umanaged C++:Come si effettua il marshalling di un puntatore a un puntatore a un int?
int foo(int ** New_Message_Pointer);
Come faccio a marshall questo per C#?
[DllImport("example.dll")]
static extern int foo(???);
Umanaged C++:Come si effettua il marshalling di un puntatore a un puntatore a un int?
int foo(int ** New_Message_Pointer);
Come faccio a marshall questo per C#?
[DllImport("example.dll")]
static extern int foo(???);
È possibile dichiarare la funzione in questo modo:
[DllImport("example.dll")]
static extern int foo(IntPtr New_Message_Pointer)
chiamare questa funzione e passare il puntatore a int array per esempio, è possibile utilizzare codice seguente:
Int32[] intArray = new Int32[5] { 0, 1, 2, 3, 4, 5 };
// Allocate unmamaged memory
IntPtr pUnmanagedBuffer = (IntPtr)Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Int32)) * intArray.Length);
// Copy data to unmanaged buffer
Marshal.Copy(intArray, 0, pUnmanagedBuffer, intArray.Length);
// Pin object to create fixed address
GCHandle handle = GCHandle.Alloc(pUnmanagedBuffer, GCHandleType.Pinned);
IntPtr ppUnmanagedBuffer = (IntPtr)handle.AddrOfPinnedObject();
e quindi passare ppUnmanagedBuffer alla funzione :
foo(ppUnmanagedBuffer);
Ti vuoi che sia
static extern int foo(IntPtr New_Message_Pointer)
La parte più difficile sarebbe probabilmente che cosa fare con esso una volta che avete che IntPtr ...
Si potrebbe desiderare di prendere una guarda a this question from SO, che si occupa del puntatore a un puntatore a una struct. È diverso, ma potrebbe farti andare nella giusta direzione.