高分求助VC转delphi ( 积分: 150 )

  • 主题发起人 主题发起人 草在墙头
  • 开始时间 开始时间

草在墙头

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将下列程序转成delphi:
struct _STATUS
{
unsigned char me1; /* 1st card status word */
unsigned char me2; /* 2nd card status word */
unsigned int MED; /* reader status */
}tstatus ;

extern "C" int cpuIccPowerUp(unsigned int Icslot,
unsigned char *respone,
unsigned char *lRep,
_STATUS *,
int ComPort,
int timeout);

void CStmddllchkDlg::OnButton28()
{
unsigned char *Cretdata = new unsigned char[500];
int i;
unsigned char Cretlen;
int nRetCode;
CString Ret="";
CString me1="";
CString me2="";
CString retdata="";
if ((nRetCode=cpuIccPowerUp(m_command1.GetCurSel(),
Cretdata,
&Cretlen,
&tstatus,
ComPort,5))!=0)
{
Ret.Format("%x",nRetCode);
Ret=" 卡片上电失败! 状态返回= "+Ret;
MessageBox(Ret);
}
else
{
for(i=0;i<Cretlen;i++)
retdata.Format(&quot;%x&quot;,Cretdata);
me1.Format(&quot;%x&quot;,tstatus.me1);
me2.Format(&quot;%x&quot;,tstatus.me2);
retdata=&quot; 上电成功,返回=&quot;+retdata + &quot; SW1=&quot;+me1+&quot; SW2=&quot;+me2;
MessageBox(retdata);
}
delete Cretdata;
}
 
type
P_STATUS=^_STATUS;
_STATUS=record
me1:char;
me2:char;
MED:Word;
end;

function cpuIccPowerUp(respone:pchar;lRep:pchar;st:P_STATUS;ComPort,timeout:integer):integer;stdcall;

procedure TCStmddllchkDlgButton28click(self)
var
Cretdata:array[0..499] of char;
i:integer;
Cretlen:char;//注意,这里作为一个字符,如果做那个函数将它当指针放字符串就KO
nRetCode:integer;
Ret:string;
me1:string;
me2:string;
retdata:string;
Begin
zeromemory(@Cretdata,sizeof(Createdata));//不知道cpuIccPowerUp怎么处理
ret:='';
me1:='';
me2:='';
retdata:='';
tstatus:_STATUS;//静态分配,如用P_STATUS必须new,despose;

if (cpuIccPowerUp(m_command1.GetCurSel(),//返回char *?
@Cretdata,
pchar(Cretlen),
@tstatus,
ComPort,5)<>0) then
begin
ret:=inttostr(nRetCode);
showmessage(ret);
end else
begin
retdata:=strcpy(@Cretdata);
me1:=tstatus.me1;
me2:=tstatus.me2;
end;
//静态空间,自动回收
end;

//看看能用不,最好确定函数的处理方式
 
后退
顶部