【问题标题】:DLL Import corrupting memoryDLL 导入损坏内存
【发布时间】:2013-06-06 06:52:59
【问题描述】:

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

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

【问题讨论】:

  • 你从哪里得到handle

标签: c#


【解决方案1】:

两个问题。

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

其次,在 API 使用的 the header that defines the types 中,NBioAPI_HANDLENBioAPI_FIR_HANDLEtypedefUINT,始终为 32 位(四个字节)长。您正在使用 IntPtr,它的大小取决于平台(在 64 位进程中将是 64 位。)将函数参数更改为 uint

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    相关资源
    最近更新 更多