繁体   English   中英

DLL导入损坏的内存

[英]DLL Import corrupting memory

我在使用dllimport Attempted to read or write protected memory. This is often an indication that other memory is corrupt时收到此错误Attempted to read or write protected memory. This is often an indication that other memory is corrupt Attempted to read or write protected memory. This is often an indication that other memory is corrupt

private const string dir2 = @"C:\NBioBSP.dll";

[System.Runtime.InteropServices.DllImport(dir2, SetLastError = true, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static extern uint NBioAPI_FreeFIRHandle(IntPtr hHandle, IntPtr hFIR); 

我这样称呼它

uint resultado = NBioAPI_FreeFIRHandle(handle, handle);

任何人都知道问题可能是什么

两个问题。

首先,调用约定是错误的。 对于定义函数的头文件 (以及在Win32平台NBioAPI定义__stdcall 的支持文件 ),您应该使用CallingConvention.StdCall

其次,在定义 API使用的类型的标头中,将 NBioAPI_HANDLENBioAPI_FIR_HANDLEtypedefUINT ,该长度始终为32位(四个字节)。 您正在使用IntPtr ,它的大小取决于平台(在64位进程中为64位。)将函数参数更改为uint

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM