请教Delphi 调用 c的DLL,参数传递问题
有一动态库中一函数.h中的原型是
extern "C" __declspec(dllimport) short __stdcall gCPUCommand(stAPDU *APDU , char *SW, char *Data, char *pchErrMsg);
typedef struct
{
char cla[3];
char ins[3];
char p1[3];
char p2[3];
char p3[3];
char data[256];
}stAPDU;
他声明的是(DLL开发说明)
函数名 short gCPUCommand(char *APUD, char *SW, char *Data, char *pchErrMsg)
C++BUILDER中的调用方法如下:
stAPDU APDU;
char chErrMsg[256],SW[10],,Data[128];
short ret; memset(chErrMsg,'\0',256);
memset(Data,'\0',128); memset(SW,'\0',10);
memset(State,'\0',3);
strcpy( APDU.cla, '00'); strcpy( APDU.ins ,'00');
strcpy( APDU.p1 , '00'); strcpy( APDU.p2 , '00');
strcpy( APDU.p3 , '00'); strcpy( APDU.data , '00');
ret = gCPUCommand( (stAPDU *) &APDU,SW,Data,chErrMsg);//正常
我写的调用方法:
方法1
CommData:pchar;
CommData:=pchar('0084000008');
ulRet := gCPUCommand(CommData,SW,pbReData,pchErrMsg);//返回Command BCC Verify Error
方法2
type sApdu=packed record
cla: pchar ;
ins : pchar ;
p1: pchar ;
p2 : pchar ;
p3 : pchar ;
data : pchar ;
end;
PsendComm=^sapdu;
sendComm:PsendComm;
sendComm^.cla:=pchar(Copy(pbSendBuf,1,2));
sendComm^.ins :=pchar(Copy(pbSendBuf,3,2));
sendComm^.p1 :=pchar(Copy(pbSendBuf,5,2));
sendComm^.p2 :=pchar(Copy(pbSendBuf,7,2));
sendComm^.p3 :=pchar(Copy(pbSendBuf,9,2));
sendComm^.data :=pchar(Copy(pbSendBuf,11,length(pbSendBuf)));
ulRet := gCPUCommand(@sendComm,SW,pbReData,pchErrMsg);//返回Command BCC Verify Error
是不是参数传错了?
extern "C" __declspec(dllimport) short __stdcall gCPUCommand(stAPDU *APDU , char *SW, char *Data, char *pchErrMsg);
typedef struct
{
char cla[3];
char ins[3];
char p1[3];
char p2[3];
char p3[3];
char data[256];
}stAPDU;
他声明的是(DLL开发说明)
函数名 short gCPUCommand(char *APUD, char *SW, char *Data, char *pchErrMsg)
C++BUILDER中的调用方法如下:
stAPDU APDU;
char chErrMsg[256],SW[10],,Data[128];
short ret; memset(chErrMsg,'\0',256);
memset(Data,'\0',128); memset(SW,'\0',10);
memset(State,'\0',3);
strcpy( APDU.cla, '00'); strcpy( APDU.ins ,'00');
strcpy( APDU.p1 , '00'); strcpy( APDU.p2 , '00');
strcpy( APDU.p3 , '00'); strcpy( APDU.data , '00');
ret = gCPUCommand( (stAPDU *) &APDU,SW,Data,chErrMsg);//正常
我写的调用方法:
方法1
CommData:pchar;
CommData:=pchar('0084000008');
ulRet := gCPUCommand(CommData,SW,pbReData,pchErrMsg);//返回Command BCC Verify Error
方法2
type sApdu=packed record
cla: pchar ;
ins : pchar ;
p1: pchar ;
p2 : pchar ;
p3 : pchar ;
data : pchar ;
end;
PsendComm=^sapdu;
sendComm:PsendComm;
sendComm^.cla:=pchar(Copy(pbSendBuf,1,2));
sendComm^.ins :=pchar(Copy(pbSendBuf,3,2));
sendComm^.p1 :=pchar(Copy(pbSendBuf,5,2));
sendComm^.p2 :=pchar(Copy(pbSendBuf,7,2));
sendComm^.p3 :=pchar(Copy(pbSendBuf,9,2));
sendComm^.data :=pchar(Copy(pbSendBuf,11,length(pbSendBuf)));
ulRet := gCPUCommand(@sendComm,SW,pbReData,pchErrMsg);//返回Command BCC Verify Error
是不是参数传错了?
...全文
相关推荐
VC/C#调用lazarus(delphi)写的dll, 演示参数传递方式
包含了普通类型的参数传递, 结构体传递, 字符串的传入/传出 还有callback等.
Delphi 调用VC DLL
演示 Delphi 调用VC DLL 参数传递
C#调用Delphi编写的非托管Dll的例子源程序
C#调用Delphi编写的非托管Dll的例子源程序。mydll.dll是使用delphi编写的,参数均为Pchar型。
VC/C#调用delphi写的dll, 演示如何进行类的传递并callback调用方的代码
VC调用Delphi DLL,并递交struct类型的参数 ,并于dll里面callback VC结构体里面的方法.
LabVIEW中如何调用WindowsAPI.pdf
LabVIEW中如何调用WindowsAPI.pdf


语言基础/算法/系统设计
