DLL导入损坏内存



我在使用dllimport 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_HANDLEtypedef 'd到UINT,始终是32位(4字节)长。您正在使用IntPtr,它具有与平台相关的大小(在64位进程中它将是64位)。修改函数参数为uint

最新更新