VC转delphi(50分)

  • 主题发起人 主题发起人 神经蛋白质
  • 开始时间 开始时间

神经蛋白质

Unregistered / Unconfirmed
GUEST, unregistred user!
今天拿到一个卡机的接口api. 本身的demo程序是VC. 我利用他的接口API调用他的DLL.把程序改为delphi.可老报错kernel32.dll. 请大虾门看.应该怎样改.下面是VC的代码:

这个是 CardData.h

#ifdef _WIN32
#define STDCALL __stdcall
#else
#define STDCALL
#endif
#ifndef SDTAPI_
#define SDTAPI_
#ifdef __cplusplus
extern "C"{
#endif

#pragma pack(1)
typedef struct tagIDCardData{
char Name[32];
char Sex[4];
char Nation[6];
char Born[18];
char Address[72];
char IDCardNo[38];
char GrantDept[32];
char UserLifeBegin[18];
char UserLifeEnd[18];
char reserved[38];
}IDCardData;

#pragma pack()

// 这里是接口API函数.CardData.dll的
int STDCALL Syn_ReadMsg(int iPortID,int iIfOpen,IDCardData *pIDCardData);


#ifdef __cplusplus
}
#endif
#endif

主要是应该把这个头文件改为delphi结构的.如何改才对!

void CSample::OnButton1()
{
int iRet;
IDCardData CardMsg;

iRet:=Syn_ReadMsg(1,0,Cardmsg);
if (iRet == 0)
{
m_name=Cardmsg.name;
}
}
 
以下是本人改写的头文件

Type
IDCardData = record
name:String;
Sex:String;
Nation:String;
Born:String;
Address:String;
IDCardNo:String;
GrantDept:String;
UserLifeBegin:String;
UserLifeEnd:String;
ReServed:String;
end;

function Syn_ReadMsg(iPortID:integer;iIfOpen:integer;pIDCardData:IDCardData):integer
stdcall
external 'CardRead.dll';

大虾看有什么问题?
 
function Syn_ReadMsg(iPortID:integer;iIfOpen:integer
var pIDCardData:IDCardData):integer
stdcall
external 'Syn_IDCardRead.dll';
 
pIDCardData:IDCardData [?]
 
Type
IDCardData = packed record ///*************
name: array[0..31] of char;
Sex: array[0..3] of char
// 都改称这样。。。下面的范围自己加了
Nation:array[] of char;
Born:array[] of char;
Address:array[] of char;
IDCardNo:array[] of char;
GrantDept:array[] of char;
UserLifeBegin:array[] of char;
UserLifeEnd:array[] of char;
ReServed:array[] of char;
end;
 
[:(] 还是 报错 kernel32.dll .[:(]
 
程序如下:
procedure TForm1.Button1Click(Sender: TObject);
var
iRet:integer;
CardMsg:IDCardData;
begin
try
iRet:=Syn_ReadMsg(1,0,@cardmsg);
except
end;

showmessage(cardmsg.name);


end;
 
function Syn_ReadMsg(iPortID:integer;iIfOpen:integer;pIDCardData:IDCardData):integer
stdcall
external 'CardRead.dll';
pIDCardData:IDCardData这里是否有错误呢.VC原函数是IDCardData *pIDCardData,好象是指针.
 
不行啊.
请问大家应该怎么该??
 
var
vBuffer: array[0..2048-1] of Char;
begin
FillChar(vBuffer, SizeOf(vBuffer), 0);
Syn_ReadMsg(1, 0, vBuffer);
end;
确认如上语句可以调用
type
tagIDCardData = packed record
Name: array [0..32-1] of Char;
Sex: array [0..4-1] of Char;
Nation: array [0..6-1] of Char;
Born: array [0..18-1] of Char;
Address: array [0..72-1] of Char;
IDCardNo: array [0..38-1] of Char;
GrantDept: array [0..32-1] of Char;
UserLifeBegin: array [0..18-1] of Char;
UserLifeEnd: array [0..18-1] of Char;
reserved: array [0..38-1] of Char;
end;
IDCardData = tagIDCardData;
PIDCardData = ^IDCardData;

function Syn_ReadMsg(
iPortID: Integer;
iIfOpen: Integer;
pIDCardData: PIDCardData
): Integer
stdcall
external 'CardRead.dll';

procedure TForm1.FormCreate(Sender: TObject);
var
iRet: Integer;
CardMsg: IDCardData;
begin
try
iRet := Syn_ReadMsg(1, 0, @CardMsg);
except
end;
ShowMessage(CardMsg.Name);
end;
 
后退
顶部