C#调用C++函数的注意事项

最近在开发一个和硬件交互的客户端,开发包是C++写的,客户端要用C#来实现,在开发中遇到一些问题,特记录下来,让自己以后备查。

函数原型

 

1、函数名称:FPITemplate

2、函数原型

     int FPITemplage(int nPort,unsigned char *psMB,int *lpLength)

3、功能说明

    用户录入3次指纹,生成指纹模板并上传。

4、入口参数

    nPort:设备类型

5、出口参数

   psMB:指纹模板 需要分配513字节的缓冲区

   lpLength:指纹模板长度 512个字节

C#中定义和调用

 

定义DLL的函数
       

1         [DllImport("JZTDevDll.dll", EntryPoint = "FPITemplate")]
2         public static extern int FPITemplate(int nPort,ref byte _psMB,ref int lpLength);

在C#中进行调用

        byte[] _psMB =  new byte[513];
        int _lpLength = _psMB.Length - 1;
        int i = FPITemplate(FPIDevDetect(),ref _psMB[0],ref _lpLength);

这样就可以取到指纹数据。

读取返回到的byte的指纹数据

string FPI_Str = "";
            if (i == 0)
            {
                FPI_Str = System.Text.Encoding.UTF8.GetString(_psMB);
             }

希望这个能帮助到园友,大家少走弯路。

posted @ 2013-05-20 12:32  localitysoft  阅读(825)  评论(1编辑  收藏  举报