1

我正在使用指纹读取器 UFP20。SDK 提供 2 个 DLL 文件(WIS_API.dll、WisCmos2.dll)。不幸的是,他们不提供 c# 演示代码。我可以连接设备并测试设备。它工作完美。

问题:我无法捕获指纹,即使捕获初始化功能工作正常。调用 WIS_Capture() 函数时出错。错误 - “此函数试图访问受保护的内存区域,这可能会损坏系统”

有关该功能的更多详细信息:-

WIS_捕获

Synopsis
         int WINAPI WIS_Capture( HANDLE hInit, int *rCount )
Parameter
        hInit        The handle returned by WIS_InitDriver()
        rCount       A value used internally by the function. The developer MUST 
                     initial this value to 0 before use.

Description :
     To snap a fingerprint from the fingerprint device to the main memory by a
     fingerprint image quality control process. The fingerprint quality control 
     cycle needs several frames of images and will continuously return the 
     status of the fingerprint after each frame of image captured.

请帮助我避免此错误。

4

2 回答 2

0

我的朋友 Avatar 是对的,您必须使用如下代码调用非托管 dll 函数:

namespace SDK_DLL_NS
   {
      internal class SDK_DLL
         {
            [DllImport("../../../SDK/SDK.dll")]
            public static extern unsafe int SDK_AMethod(int devHandle, IntPtr buf, int length);
            public const int MAX_LEN = 12345;  
.....
    }
}

现在,这只是工作的接口部分,根据定义,.NET 虚拟机内存不是固定的,这是 dll 所期望的,幸运的是,我们有 System.Runtime.InteropServices 命名空间来帮助它的 GCHandle 结构,它提供了一个从非托管代码访问托管对象的方法。所以我认为代码可能是这样的,我们需要分配一些内存“本地代码”:

SDKdllBuffer = new byte[SDK_DLL.MAX_LEN];
pinnedBuffer = GCHandle.Alloc(SDKdllBuffer, GCHandleType.Pinned);

unsafe
     {
        SDK_DLL.SDK_AMethod(handle, pinnedBuffer.AddrOfPinnedObject(),MAX_LEN);
}

希望这能给你一个想法。祝你好运。胡安

于 2011-09-12T23:20:28.880 回答
0

“此功能试图访问受保护的内存区域,可能会损坏系统”

这听起来类似于从托管代码调用非托管代码时遇到的错误。

根据THIS(您需要一直向下滚动才能看到答案),您可能需要使用 References -> Com 将这些 dll 添加到您的项目解决方案中。这将创建一个托管代码包装器,以便您可以在代码中使用它们。

于 2009-06-19T13:09:47.913 回答