C++ Builder 代码改写为Delphi代码(200分)

  • 主题发起人 主题发起人 lingxin
  • 开始时间 开始时间
L

lingxin

Unregistered / Unconfirmed
GUEST, unregistred user!
int __stdcall (*mf_ReadRfid)(unsigned char *id, unsigned char *type);
void __fastcall TForm1::Button8Click(TObject *Sender)
{
(FARPROC&) mf_ReadRfid = GetProcAddress(hDll,"mf_ReadRfid");
if (mf_ReadRfid != NULL)
{
unsigned char snr[8];
int retVal;
unsigned char type = 0;
AnsiString msg="";
mf_Led(1);
mf_Beep(1);
retVal = mf_ReadRfid(snr, &type);
if (retVal == ERR_NOERROR)
{
DWORD id=0;
AnsiString sid="";
msg = "";
id = (DWORD)(snr[0]<<24) |
(DWORD)(snr[1]<<16) |
(DWORD)(snr[2]<<8) |
snr[3];
msg.printf(&quot;卡号:%010lu 厂商代码:%02X&quot;,id,type);
sid.printf(&quot;%010lu&quot;,id);
Edit6->Text = sid;
Edit7->Text = IntToHex(type,02);
}
else
{
msg = GetErrMsg(retVal);
}
Memo1->Lines->Append(msg);
mf_Led(0);
mf_Beep(0);
}
else
{
Application->MessageBox(&quot;DLL函数定位错误(mf_ReadSnr)!&quot;,&quot;Error&quot;,MB_OK);
}
}
 
你的有些函数你自己再转换一下,包括常量
————————————————————————————
type
TReadRfid = function (AId: array of Byte;
var AType: Byte): Integer;
stdcall;
const
ERR_NOERROR = 0;
procedure TForm1.Button1Click(Sender: TObject);
var
mf_ReadRfid: TReadRfid;
snr: array[0..7] of Byte;
retVal: Integer;
nType: Byte;
Msg: string;
nID: DWORD;
sID: string;
begin
mf_ReadRfid := GetProcAddress(hDll,'mf_ReadRfid');
if Assigned(mf_ReadRfid) then
begin
nType := 0;
Msg := '';
// 这两个函数按照上面的方法自己转换吧
// mf_Led(1);
// mf_Beep(1);
retVal := mf_ReadRfid(snr, nType);
if retVal = ERR_NOERROR then
begin
msg := '';
nId := DWORD(snr[0] shl 24) or
DWORD(snr[1] shl 16) or
DWORD(snr[2] shl 8) or snr[3];
msg := Format('卡号:%010lu 厂商代码:%02X', [nid, nType]);
sID := Format('%010lu',id);
Edit6.Text := sID;
Edit7.Text := IntToHex(nType, 2);
end
else
begin
// msg := GetErrMsg(retVal);
end;
Memo1.Lines.Append(msg);
// mf_Led(0);
// mf_Beep(0);
end
else
begin
Application.MessageBox('DLL函数定位错误(mf_ReadSnr)!', 'Error', MB_OK);
end;
end;
 
照着一句句的写就行了
 
李大侠也学习顶
 
调试返回错误,
 

Similar threads

I
回复
0
查看
1K
import
I
I
回复
0
查看
551
import
I
I
回复
0
查看
573
import
I
I
回复
0
查看
800
import
I
后退
顶部