如何转换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);
调用函数
void Function1()
{
IntPtr PPtr=N_AllocPt1dArray(n, ref S);
}
现在我需要转换
PPtr
到一个数组(数组是 demo[]
),其中演示由public unsafe struct demo
{
public int x ;
public int y ;
public int z ;
}demo DEMO;
最佳答案
尝试这个:
array[0] = (demo)System.Runtime.InteropServices.Marshal.PtrToStructure(PPtr , typeof(demo));
更新 :
this的解决方案2 page是你所需要的。
关于c# - 如何将 IntPtr 转换为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31854195/