【发布时间】:2019-02-26 21:33:57
【问题描述】:
一个指针从 C++ dll 传递给我,如下所示:
[DllImport("myfile.dll", EntryPoint = "LoadFile", SetLastError = true, CharSet = CharSet.None)]
public static extern IntPtr dLoadFile(string x);
IntPtr p = dLoadFile("myfile");
//Do things with p.
Marshal.FreeHGlobal(p) //crash on this line with exception below.
System.Runtime.InteropServices.COMException: '一个或多个参数 无效(HRESULT 异常:0x80000003)'
我应该释放分配给 IntPtr 的内存吗?如果是的话,如何正确地做到这一点? 显然,Marshal.FreeHGlobal() 似乎不是要走的路……
谢谢
【问题讨论】:
标签: c# dll marshalling