DLL导入破坏内存

时间:2013-06-05 22:35:14

标签: c#

我在使用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);

任何人都知道问题是什么

1 个答案:

答案 0 :(得分:5)

两个问题。

首先,调用约定是错误的。每个the header file that defines the function(以及the supporting file that defines NBioAPI作为Win32平台上的__stdcall),您应该使用CallingConvention.StdCall

其次,在API使用的the header that defines the types中,NBioAPI_HANDLENBioAPI_FIR_HANDLEtypedef'到UINT,总是32位(四个字节) ) 长。您正在使用IntPtr,它具有与平台相关的大小(在64位进程中将为64位。)将函数参数更改为uint