c#调用c++ dll出现“尝试读取或写入受保护的内存”提示
用c++写的一个调用pcl功能的dll,在c++控制台下工作正常,写成dll提供c#调用时,却出现“尝试读取或写入受保护的内存”的提示。分别调整了CallingConvention的参数,结果如下:
CallingConvention.Winapi:尝试读取或写入受保护的内存。
CallingConvention.ThisCall:Debug Assertion Failed!提示窗口。
CallingConvention.StdCall:尝试读取或写入受保护的内存。
CallingConvention.StdCall:无效的非托管调用约定: 必须是 stdcall、cdecl 或 thiscall 之一。
CallingConvention.Cdecl:尝试读取或写入受保护的内存。
代码如下:
代码是调用PCLTest.dll中的PLYConvert方法,将pcd转为ply。dll的dumpbin查询结果如下:
请教如何解决该问题?
CallingConvention.Winapi:尝试读取或写入受保护的内存。
CallingConvention.ThisCall:Debug Assertion Failed!提示窗口。
CallingConvention.StdCall:尝试读取或写入受保护的内存。
CallingConvention.StdCall:无效的非托管调用约定: 必须是 stdcall、cdecl 或 thiscall 之一。
CallingConvention.Cdecl:尝试读取或写入受保护的内存。
代码如下:
[System.Runtime.InteropServices.DllImport(@"D:\新整理\开发\MSC++\PCLLibs\PCLTest\Debug\PCLTest.dll", EntryPoint = "PLYConvert", CallingConvention = CallingConvention.Cdecl)]
public extern static int PLYConvert(string pcdPath, string savePath, float searchRadius, float mu, int nearestNeighbors);
private void Form1_Load(object sender, EventArgs e)
{
PLYConvert(@"D:\新整理\安装与资源\点云数据集\PCDdata\bunny.pcd", @"d:\bunny.ply", 15.0f, 5.0f, 100);
MessageBox.Show("ok");
}
代码是调用PCLTest.dll中的PLYConvert方法,将pcd转为ply。dll的dumpbin查询结果如下:
Dump of file pcltest.dll
File Type: DLL
Section contains the following exports for PCLTest.dll
00000000 characteristics
5B3603A8 time date stamp Fri Jun 29 18:02:16 2018
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 000444C5 PLYConvert = @ILT+17600(_PLYConvert)
Summary
3000 .data
5000 .idata
18000 .rdata
5000 .reloc
1000 .rsrc
8B000 .text
3F000 .textbss
1000 .tls
请教如何解决该问题?
...全文


