日期:2014-05-17  浏览次数:20868 次

c# 调用 vc dll 函数方法
需要写刷卡器系统, 调用vc dll,有部分我调用成功了,如下:

 icdev = IC.rf_init_com(3,9600);


//对设备进行初始化
public unsafe class IC
{
    [DllImport("MasterRD.dll", EntryPoint = "rf_init_com", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern int rf_init_com(int port, Int64 baud);
}


现在就差验证密匙的调用不成功,

下面是vc dll 函数说明
Mifareone 授权2

/*********************************************************

功能:用当前指定的密钥对卡片授权认证

参数: icdev: 通讯设备标识符

       mode: 密码验证模式

       block:要验证密码的绝对块号

       key:   下载的密钥(6Byte),(我加的,key 验证密匙,6字节)

返回:成功则返回0

说明:model=0x60:验证A密钥

       model=0x61:验证B密钥

*********************************************************/

int (WINAPI *rf_M1_authentication2)(unsigned short icdev,unsigned char mode,unsigned char block,unsigned char  *key);


我写了2种方法:如下,但是都是返回值错误,本该返回0,2中方法都是返回1, 求助::写代码最好,主要感觉问题出在最后一个参数,也就是密匙key。
调用:
                ////方法1
                //byte[] key = new byte[6] { 255, 255, 255, 255, 255, 255 };
                //Int16 checkIC_pwd = (short)IC.rf_M1_authentication2(icdev1,mode,block, ref key[0]);

                //方法2

                byte[] dd = new byte[6];
                dd[0] = (byte)0xFF;
                dd[1] = (byte)0xFF;
                dd[2] = (byte)0xFF;
                dd[3] = (byte)0xFF;
                dd[4] = (byte)0xFF;
                dd[5] = (byte)0xFF;
                int xx = IC.rf_get_device_number(ref dve);
                int checkIC_pwd = IC.rf_M1_authentication2(dve, 0x60, block,ref dd[0]);


下面是定义:
    //方法1
    //[DllImport("MasterRD.dll", EntryPoint = "rf_M1_authentication2", SetLastError = true, CharSet =      CharSet.Ansi, ExactSpelling = true, CallingConvention =