注册 登录
编程论坛 VB6论坛

delphi 的函数VB里怎写,大家来帮忙一下

whtydn 发布于 2012-08-14 17:41, 508 次点击
DELPHI读写一个DLL如下
function Read_CardID(aData :Pchar): Integer;
     stdcall; external 'TemicUsbDll.dll' name 'Read_CardID';

procedure TForm8.BitBtn1Click(Sender: TObject);
var
  CardID :array[0..3] of char;
  str :String;
  i,iresult:Integer;
begin
    if( Read_CardID(CardID) <> 0 ) then
    begin
    SPK_Beep(2);   //响声函数
    exit;
    end;
     SPK_Beep(1);
      str :='';
     for i:=0 to 3 do
     str :=str+ inttohex(ord(CardID[i]),2);
     insert('',str,3);
     insert('',str,6);
     insert('',str,9);
     MaskEdit1.Text :=str;
end;

如果用VB6怎写呢?下面这样正正确吗?
'读卡号
Public Declare Function Read_CardID Lib "TemicUsbDll.dll" (ByVal CardID As String) As Integer
调用时这样
Dim CardID As String * 30
iResult = Read_CardID(CardID)
    If iResult <> 0 Then
        MsgBox ("读不到" & iResult)
    Else
        MsgBox Hex(Asc(CardID))
    End If

如果是这样写 只能读到一部分,Pchar在delphi中是数组类型的, 如果VB里用数组读。 怎定义呢? 请大家帮忙
1 回复
#2
bczgvip2012-08-14 19:14
Public Declare Function Read_CardID Lib "TemicUsbDll.dll" ( CardID As any) As long

Dim CardID(0 to 3) As byte '嗯,好像上限不对。自己改吧
iResult = Read_CardID(CardID(0))
    If iResult <> 0 Then
        MsgBox ("读不到" & iResult)
    Else
        MsgBox Hex(Asc(CardID)) '可能类型不对,自己改吧
    End If

CardID 是什么样的数据?例如?
1