就一句 VB 转 Delphi 请进来看一下 (100分)

  • 主题发起人 主题发起人 jun
  • 开始时间 开始时间
J

jun

Unregistered / Unconfirmed
GUEST, unregistred user!
Public Declare Function MF_Request Lib "SCReader.dll" (ByVal hPort As Long, ByVal bytMode As Byte, pTagType As Byte) As Long
'//------------------------------------------------------------// 
Dim bytMode As Byte
Dim atq(2) As Byte
bytMode = &H52
If 0 <> MF_Request(m_hPort, bytMode, atq(0)) Then
txtATQ.Text = ToHexString(atq(0)) &amp
ToHexString(atq(1))
Else
MsgBox "Request Failed!"
End If

我转为DELPHI 代码
Function MF_Request(hPort:integer
bytMode:Byte
pTagType:Byte):smallint
stdcall
far;external 'SCReader.dll' name 'MF_Request';

//******************//
var bytMode : Byte;
ATQ : array[1..2] of Byte;
begin
bytMode := $52;
If 0 <> MF_Request(m_hPort,bytMode,ATQ[1]);
showmessage(OK'+ATQ[1]+??? )
else
showmessage('Error!');

???? ATQ[1] 这个byte型 老不对 帮我改改!
 
这样试一试:
Function MF_Request(var hPort:integer
var bytMode, pTagType:Byte):smallint
stdcall
far;external 'SCReader.dll' name 'MF_Request';

//******************//
var bytMode : Byte;
ATQ : array[1..2] of Byte;
begin
bytMode := $52;
If 0 <> MF_Request(m_hPort,bytMode,ATQ[1]) then
showmessage(OK'+ATQ[1]+??? )
else
showmessage('Error!');
 
从VB上看结果看:
Function MF_Request(hPort:integer
bytMode:Byte
pTagType:Byte):smallint
stdcall
far;external 'SCReader.dll' name 'MF_Request';
If 0 <> MF_Request(m_hPort, bytMode, atq(0)) Then
txtATQ.Text = ToHexString(atq(0)) &amp
ToHexString(atq(1))

pTagType应该传的是个指针.你能不能看一下MF_Request的原型。
如果是的话:
type
PTTagType = ^TTagType;
TTagType = array[0..1] of byte;

Function MF_Request(hPort:integer
bytMode:Byte
pTagType:PTTagType ):smallint
stdcall
far;external 'SCReader.dll' name 'MF_Request';

var
ATQ : array[0..1] of Byte;
pATQ: PTTagType;
begin
pATQ := PTTagType(@(ATQ));
If 0 <> MF_Request(m_hPort,$52,pATQ ) then
showmessage('OK,'+ IntToHex(ATQ[0], 2) + IntToHex(ATQ[1], 2) )
else
showmessage('Error!');
end;
 
apw,你的也通不过!
pTagType 是 [OUT] 2字节的响应信息,可用来指示类型。
VB里头得到 atq(0)=4 atq(1)=0 再转为HEX 得 0400
 
不是很难啊
 
VB语法:
Public Declare Function MF_Request Lib "SCReader.dll" (ByVal hPort As Long, ByVal bytMode As Byte, pTagType As Byte) As Long
VB演示:
Dim bytMode As Byte
If cmbRequestMode.ListIndex = 0 Then
bytMode = &amp;H52
Else
bytMode = &amp;H26
End If
Dim atq(2) As Byte
If 0 <> MF_Request(m_hPort, bytMode, atq(0)) Then
txtATQ.Text = ToHexString(atq(0)) &amp
ToHexString(atq(1))
Else
MsgBox "Request Failed!"
End If
结果 txtATQ.Text=0400
/// 我把它转为delphi----------------------------------------------
Function MF_Request(hPort:integer
bytMode:Byte
pTagType:Byte):integer
stdcall;far;external 'SCReader.dll' name 'MF_Request';
代码
procedure TForm1.Button3Click(Sender: TObject);
var
bytMode : Byte;
ATQ : array[0..1] of byte;
begin
bytMode := $52;
If 0 <> MF_Request(m_hPort,bytMode ,ATQ[0]) then
showmessage(IntToHex(ATQ[0], 2) + IntToHex(ATQ[1], 2))
else
showmessage('Error!');
end;
不出错取得 0000 就是返回到 ATQ[0]) 什么也没有, 各位再帮我看看!
 

Similar threads

后退
顶部