2013-06-05 61 views
0

我同时使用dllimport的Attempted to read or write protected memory. This is often an indication that other memory is corruptDLL导入破坏内存

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); 

任何人都知道这个问题可以

+0

你从哪里得到'handle'? – Patashu

回答

5

两个问题收到此错误。

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

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