想调用指昂的指纹系统的PC端匹配的API,
API说明如下:
 1: Match two character file on PC 
    int WINAPI Match2Fp(unsigned char* Src,unsigned char* Dst); 
           Parameter: Src: source character file buffer. 
                      Dst: destination    character file buffer. 
            Return: function return a score of one matching. Basicly , Should the  number be equal or above 50, that indicates successful matching. And the higher the number, the more precise the matching.   
用C++调用该API已成功,现想用C#调用,调用代码如下:
[DllImport("ARTH_DLL.dll")]
 static extern int  Match2Fp(ref byte[] Src, ref byte[] Dst); 出现异常,未处理BadImageFormatException.试图加载格式不正确的程序。(异常来自 HRESULT:0x8007000B)网上查了,好多答案说是,因为dll文件是在64位机下编译的,而开发环境是32位机。我的开发环境是32位的,用VC调用也是在此机上实现的。试了网友的解决的方法未能解决,因而我想这个原因应该可以排除。

解决方案 »

  1.   

    和64位有没有关系不太清楚,但即使是32位编译出来的,你的调用方式也是不对的,传数组时,不要用ref
    [DllImport("ARTH_DLL.dll")]
     static extern int Match2Fp(byte[] Src, byte[] Dst);  
      

  2.   

    unsigned char* [MarshalAs(UnmanagedType.LPArray)]byte[](Intptr)
    http://topic.csdn.net/u/20091124/21/dabd5228-514e-4c5b-a794-aae11f41dab5.html
      

  3.   

    在你C#的
    项目设置 - 编译 - 目标平台
    选择"X86",而不是"Any CPU"面向Any CPU的C#程序,在X64上就会以64bit方式运行,也就会尝试着加载64bit的连接库。
    这是如果dll是32位时候,就会抛出BadImageFormatException异常。
      

  4.   

    如果你确认dll是64位的,那么你的32位开发机就没有办法使用它。
      

  5.   

    刚问了那边的技术支持,dll是32位的。而且我用VC已经调用成功,我想不是这个问题的。
      

  6.   

    和64位有没有关系不太清楚,但即使是32位编译出来的,你的调用方式也是不对的,传数组时,不要用ref
    [DllImport("ARTH_DLL.dll")]
     static extern int Match2Fp(byte[] Src, byte[] Dst); 
    unsigned char* [MarshalAs(UnmanagedType.LPArray)]byte[](Intptr)
    http://topic.csdn.net/u/20091124/21/dabd5228-514e-4c5b-a794-aae11f41dab5.html
      

  7.   

    [MarshalAs(UnmanagedType.LPArray)]如梦大神已经写的很清楚了~~~    
      

  8.   

    我是楼主。
    不是参数问题,不是32位,64位问题。我在控制端应用程序测试成功了。但是windows应用程序就是会报这错误。有哪位高人知道到底是为什么啊。
      

  9.   

    和64位有没有关系不太清楚,但即使是32位编译出来的,你的调用方式也是不对的,传数组时,不要用ref
    [DllImport("ARTH_DLL.dll")]
     static extern int Match2Fp(byte[] Src, byte[] Dst);