Function Integer DC_Mif_Read(Integer bAddr ,Ref String bData ) Library "Fox_DC.dll"
Function Integer DC_Mif_Write(Integer bAddr , Ref String bData ) Library "Fox_DC.dll"这两个函数是PB中的声明说明如下:DC_Mif_Write
DC_Mif_Write 函数向卡片内的指定块地址写入一字符串。WORD DC_Mif_Write
               (
               BYTE _bAdr,
               BYTE *_bData
               );
 
参数
_bAdr 要写入的块地址。对于Mifare S50卡,其范围为(1 - 63),对于Mifare L10卡,其范围为(2 - 11), Mifare 1102 其范围是(2 – 15);Token其范围是(2 – 15)。 _bData 无符号字符型指针,其内容为要写入到卡片内的ASC码形式的字符串。Mifare S50应确保已分配给_bData指针至少32个字节的空间,其余8字节就好。 返回值
如果函数调用成功,返回值为0。如果函数调用失败,返回值不为0。如需得到错误描述,请调用DC_GetLastError。DC_Mif_Read
DC_Mif_Read 函数从卡片内的指定块地址读取一字符串。WORD DC_Mif_Read
               (
               BYTE _bAdr, 
               BYTE *_bData
               ) 
参数
_bAdr要读取的块地址。对于Mifare S50卡,其范围为(0 - 63);对于Mifare L10卡,其范围为(0 - 11),其中有连续两个块读的内容是一样的;Mifare 1102 其范围是(0 – 15);Token其范围是(0 – 15)。 _bData 无符号字符型指针,指向从卡片存储区内读到的字符串的ASC码并返回给应用程序。读Mifare S50的卡应确保已分配给_bData指针至少32个字节的空间,Mifare L10 至少16字节空间,其余8字节就可。  返回值
如果函数调用成功,返回值为0。如果函数调用失败,返回值不为0。如需得到错误描述,请调用DC_GetLastError。 
  请问在C#中如何调用?????

解决方案 »

  1.   

    我的调用方式是:
     [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Write", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
            public static extern int DC_Mif_Write(UInt16 bAddr,ref  StringBuilder bData);写的时候没出什么错误,倒是可以写进卡里
    但读的时候,读出来的是空
     DC_Mif_Read函数该如何调用??
      

  2.   

    vb 中的声明是这样的
    Public Declare Function DC_Mif_Read Lib "Fox_DC" (ByVal bAddr As Byte, ByVal bData As String) As IntegerPublic Declare Function DC_Mif_Write Lib "Fox_DC" (ByVal bAddr As Byte, ByVal bData As String) As Integer
      

  3.   

    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
            public static extern int DC_Mif_Read(int bAddr,string bData); 
    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Write", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
            public static extern int DC_Mif_Write(int bAddr,string bData); 这样试试
      

  4.   

    to Fibona
    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
            public static extern int DC_Mif_Read(int bAddr,string bData); 
    这样定义的话,读到的值没法返回
      

  5.   

    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
            public static extern int DC_Mif_Read(int bAddr,ref string bData); 这样试试呢?
      

  6.   

    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read")] 
            public static extern int DC_Mif_Read(UInt16 bAddr,ref string bData); string udd = ""; 
    DC_Mif_Read(0, ref  udd);到这句就出错了 
    引发类型为“System.ExecutionEngineException”的异常。 
    大家帮忙 
      

  7.   

    以前做M1读卡的时候主要取决然于DLL文件,,如果说DLL中的此方法的话会好一些,具体要看DLL文件中的了,因为毕竟你是通过调用DLL文件中的方法去启动卡的
      

  8.   

    是通过DLL文件去启动读卡器的
      

  9.   

    郁闷  哪个图不能贴,申请了好久了  郁闷,管理员在干什么。火大的很
    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
            public static extern int DC_Mif_Read(int bAddr,ref string bData); 
      

  10.   

    上面的方法会
    引发类型为“System.ExecutionEngineException”的异常。
      

  11.   

    楼主,我不知道你这读卡器是读数的,我只说一下以前我的读卡方式,是通过事件来返回的,即发送个命令如果命令正确会触发事件,然后通过事件来得到返回值的,具体要看你的DLL以及卡的方式,你老是纠缠在DLL方法上,我认为不可取,
      

  12.   

     public static extern int DC_Mif_Write(UInt16 bAddr,ref  StringBuilder bData); 
    这句改成 public static extern int DC_Mif_Write([MarshalAs(UnmanagedType.LPArray)]int bAddr,ref string bData); 
    试试?我以前也也过,多年没接触这个东西了。
      

  13.   

    发一个参数对照表。。
    HANDLE  void*  System.IntPtr 
     
    BYTE  unsigned char  System.Byte 
     
    SHORT  short  System.Int16 WORD  unsigned short  System.UInt16 
     
    INT  int  System.Int32 UINT  unsigned int  System.UInt32 LONG  long  System.Int32 BOOL  long  System.Int32 DWORD  unsigned long  System.UInt32 
     
    ULONG  unsigned long  System.UInt32 CHAR  char  System.Char  
     
    LPSTR  char*  System.String 或 System.Text.StringBuilder
     
    LPCSTR  Const char*  System.String 或 System.Text.StringBuilderLPWSTR  wchar_t*  System.String 或 System.Text.StringBuilderLPCWSTR  Const wchar_t*  System.String 或 System.Text.StringBuilder
     
    FLOAT  Float  System.Single 
     
    DOUBLE  Double  System.Double 
      

  14.   

    所以你
     public static extern int DC_Mif_Write(UInt16 bAddr,ref  byte[] bData); 
      

  15.   


    加上这句就完美了[DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern int DC_Mif_Read(UInt16 bAddr,ref  byte[] bData);
      

  16.   

    前面应该一样,调试看看数据
      StringBuilder 修改string看看
      

  17.   


    string udata1 =TextBox1.Text;
    string udata2 = TextBox2.Text;
    string udata3 =TextBox3.Text;
    byte[] bdata1 = Encoding.Default.GetBytes(udata1);
    byte[] bdata2 = Encoding.Default.GetBytes(udata2);
    byte[] bdata3 = Encoding.Default.GetBytes(udata3);
    write = ICCard.DC_Mif_Write(4, ref bdata1);
    write = ICCard.DC_Mif_Write(5, ref bdata2);
    write = ICCard.DC_Mif_Write(6, ref bdata3);
    假如textbox1是两个汉字 那么 byte[] bdata1 是4维的
    到调用 ICCard.DC_Mif_Write(4, ref bdata1);
    此时 bdata1只有1维的
      

  18.   


    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern int DC_Mif_Read(UInt16 bAddr,ref  byte[] bData);我有下面调用
    byte[] udata = new byte[255];
    read = ICCard.DC_Mif_Read(4,ref udata);
    引发类型为“System.ExecutionEngineException”的异常。
      

  19.   

    是的,是考勤的刷卡或公交卡,之类的
    读卡器是向开发商买的,他们提供二次开发文档和dll
    我们自己调用
      

  20.   

    以前总是C#搞C++,
    LZ这次是C#搞PB
      

  21.   

    [DllImport("FOX_DC.dll", EntryPoint = "DC_Mif_Read", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]  
      public static extern int DC_Mif_Read(int bAddr,ref string bData); 
    引发类型为“System.ExecutionEngineException”的异常。
      

  22.   

    DllImport导入DLL声明一下就可以便用了!~
      

  23.   

    这样的东西是用C++搞吧.简单.不像c#那样byte来byte去.太没有意思了!C++的字符串就可以在网络中传输.还可以直接使用这些类库.C#还要转化.