2013-06-05 95 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