Dll中申明函数原型:
C语言申明
int WINAPI rfReader_M1_read(long ReaderHandle,unsigned short icdev, unsigned char KeyA_B, unsigned char block,  unsigned char * key, unsigned char *pData);
VB调用如下:
  Dim TF As Long      '返回标志
  Dim bySourByte(256) As Byte
  Dim szDestString(256) As Byte
  Dim strbuf As String * 256
  Dim strbuf1 As String * 256
strbuf1 ="FFFFFFFFFFFF"
Call StringToByte(strbuf1, 12, szDestString(0))
TF = rfReader_M1_read(RHandle, 0, 0, 4, szDestString(0), bySourByte(0))我在Delphi申明如下:
function rfReader_M1_read(ReaderHandle:LongInt;icdev:Word;KeyA_B:Byte;block:Byte;key,pSnr:pchar):Integer;stdcall;external 'MifareOne.dll';
怎么样把它翻译成Delphi语言,谢谢!

解决方案 »

  1.   

    试试这样,如果不行再调试:function rfReader_M1_read(ReaderHandle:LongInt;icdev:Word;KeyA_B:Byte;block:Byte;key,pSnr:pchar):Integer;stdcall;external 'MifareOne.dll';procedure TForm1.Button1Click(Sender: TObject);
        procedure StringToByte(pBuf: PChar; nLen: integer; pDest: array of Byte);
        var
            nLBound: integer;
            nUBound: integer;
            i: integer;
        begin
            nLBound := Low(pDest);
            nUBound := High(pDest);
            If(nLen > nUBound - nLBound) Then
                nLen := nUBound - nLBound;
            for i := 0 to nLen do
                pDest[i + nLBound] := Ord(pBuf[i]);
        end;
    var
        TF: longint;
        bySourByte: array[0..256] of Byte;
        szDestString: array[0..256] of Byte;
        strbuf: array[0..256] of char;
        strbuf1: array[0..256] of char;
        RHandle: LongInt;
    begin
        StrPCopy(strbuf1, 'FFFFFFFFFFFF');
        StringToByte(strbuf1, 12, szDestString);
        TF := rfReader_M1_read(RHandle, 0, 0, 4, @szDestString, @bySourByte);
    end;
      

  2.   

    不行呀?StringToByte 只是把一个字符的内容对应到Byte数组里,我的要求是把两个字符分别写到Byte的高位和低位,应该怎么做呀?