dna911 2014-09-03 06:17 采纳率: 0%
浏览 922

求教,用delphi 调用 c++ 编写的一卡能读卡函数,出现地址错误

用delphi,调用一卡通的读卡函数,总是出错,请大家帮我看看吧

C++定义:
原型:ReadUid_cst(int& szCardType ,unsigned char* szData)
输入参数:无
输出参数:szCardType:卡类型,1:13.56,2:2.4
szData:UID
返回值:成功返回1,

typedef struct _USERDATA_MM1
{
char szName[14]; //姓名
unsigned char nSex; //性别
unsigned char nCertType; //证件类型
char szCertCode[20]; //证件号
unsigned char bzMobile[6]; //手机号码
unsigned int nCardSn; //卡序号
char szUserID[10]; //工号
unsigned char nCardType; //卡类型
unsigned char nDayCountLimit; //日限次数
unsigned int nDayMoneyLimit; //日限金额

char szDept[12];                      //部门
unsigned char bzUserPsw[3];           //用户密钥
unsigned char bzStartDate[4];         //开始时间
unsigned char bzExpiryDate[4];        //有效期限
unsigned short wLssj;                 //流水号

unsigned int nBalance;                //预充余额(分),读取信息时为卡余额

}USERDATA_MM1, *LPUSERDATA_MM1;

delphi xe3 的程序代码:
Type
PUCard = ^Ucard;
Ucard = packed record
szName : array[0..13] of Byte; //姓名
nSex : Byte; //性别
nCertType : Byte; //证件类型
szCertCode : array[0..19] of Byte; //证件号
bzMobile : array[0..5] of byte; //手机号码

nCardSn        : Word;                            //卡序号
szUserID       : array[0..9]  of Byte;              //工号
nCardType      : Byte;                             //卡类别
nDayCountLimit : Byte;                         //日限次数
nDayMoneyLimit : Word;                         //日限金额

szDept         : array[0..11] of Byte;                          //部门
bzUserPsw      : array[0..2]  of byte;          //用户密钥
bzStartDate    : array[0..3]  of byte;          //开始时间
bzExpriyDate   : array[0..3]  of byte;          //有效期限
wLssj          : Word;                        //流水号

nbalance       : Word;                        //预充余额(分),读取信息时为卡余额

end;

function ReadUid_cst(var szCardType:Word; szData:PUCard):Int16;stdcall; //cdecl
external 'cstcard.dll' name 'ReadUid_cst';

procedure TForm1.btn1Click(Sender: TObject);
var
szCardType : Word;
szData : Ucard;
psz : PUCard;
tmp : string;
rcode : Int16;
begin
psz:= @szdata;
rcode := ReadUid_cst(szCardType,psz);
Self.Caption := IntToStr(rcode);

//tmp := PAnsiChar(@szdata.szCertCode);
//Self.lbl1.Caption := tmp;
end;

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-03-24 19:59
    关注

    该回答引用ChatGPT-3.5

    你提供的信息很有限,无法确定问题的确切原因。但根据你提供的信息,这个错误可能是由以下原因导致的:

    • 参数类型不匹配。确保在 Delphi 中传递的参数类型与 C++ 函数的参数类型匹配。检查 Delphi 和 C++ 中的数据类型是否相同,并且顺序是否正确。
    • 函数名或库名错误。确保在 Delphi 中调用正确的函数名和库名。检查库名是否正确,并确保 C++ 函数使用了正确的函数名。
    • 内存分配错误。在 Delphi 中分配内存的方式可能与在 C++ 中分配内存的方式不同。确保 Delphi 分配的内存与 C++ 函数期望的内存类型和大小匹配。
    • 代码中可能存在其他错误。例如,使用未初始化的变量或数组越界等。

    为了解决这个问题,你可以尝试以下方法:

    • 确保在 Delphi 中正确地声明了 C++ 函数的原型,参数和返回值类型。
    • 检查 Delphi 中传递的参数类型和顺序是否与 C++ 函数期望的参数类型和顺序相同。
    • 检查库名和函数名是否正确。
    • 在 Delphi 中分配内存时,确保分配的内存与 C++ 函数期望的内存类型和大小匹配。
    • 使用调试器来检查代码中是否存在其他错误。

    希望这些建议能帮助你解决问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题