如何将 转换IntPtr为数组。实际上我从非托管 dll 调用了该函数。它返回IntPtr。现在我需要将其转换为数组。请任何人给出一个想法。代码片段如下。
Unmanaged function declared
[DllImport("NLib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe IntPtr N_AllocPt1dArray(NL_INDEX n, ref stacks S);
Run Code Online (Sandbox Code Playgroud)
调用函数
void Function1()
{
IntPtr PPtr=N_AllocPt1dArray(n, ref S);
}
Run Code Online (Sandbox Code Playgroud)
现在我需要转换PPtr为数组(数组是demo[])。其中 demo 是由
public unsafe struct demo
{
public int x ;
public int y ;
public int z ;
}demo DEMO;
Run Code Online (Sandbox Code Playgroud)
Meh*_*med -1
尝试这个:
array[0] = (demo)System.Runtime.InteropServices.Marshal.PtrToStructure(PPtr , typeof(demo));
Run Code Online (Sandbox Code Playgroud)
更新 :