在delphi编写的com中调用了vc的动态连接库,引起内存混乱,求解决方法 delphi编写的com,其中调用了vc编写的dll动态连接库,到了后期出现了内存问题,有时会有程序写内存地址的错误,有时会出现变量值莫名其妙的发生了变化。因为对delphi和vc都不很熟悉,所以来此求救。问题如果解决另外还有分值奉上。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是不是stdcall 和 farcall的区别? 是stdcall方式,代码很多,大概是这样: function test():Integer; ……………… a:=func1(); //返回值为0(integer) b:=func2(…………); //func2调用了vc的dll中的方法 showmessage(a); //在这里,a的值已经变成999 ……………… end; function func2(acct_nbr:String; bill_charge:Integer; real_pay:Integer; flag:integer; a_ser_no:String; a_date:String):Integer; var AdoRs: OleVariant; acctNum:PChar; billCharge:Integer; realPay:Integer; flagType:Integer; staffId:Integer; staffAreaId:Integer; aSerNo:PChar; aDate:PChar; returnVal:Integer; begin AdoRS:=RunSql('select bt_staff_area_id, bt_staff_id ……'); GetMem(acctNum, 17); strpcopy(acctNum, acct_nbr); aSerNo := PChar(a_ser_no); aDate := PChar(a_date); billCharge:=bill_charge; realPay:=real_pay; flagType:=flag; staffId:=strToInt(trim(AdoRS.fields['bt_staff_id'].value)); staffAreaId:=strToInt(AdoRS.fields['bt_staff_area_id'].value); //*=999 if AdoRs.state<>stClosed then AdoRs.Close; returnVal:=writeoff(acctNum, billCharge, realPay, flagType, staffId, staffAreaId, aSerNo, aDate);//vc的dll中的方法 if returnVal<>0 then fucn2:=1 //返回值 else func2:=0; freeMem(acctNum); end;end.定义:FUNCTION writeoff(acct_nbr:PChar; bill_charge:Integer; real_pay:Integer; flag:integer; staff_id:integer; staff_area_id:integer; aser_no:PChar; adate:PChar ):integer; stdcall; external 'a.dll' name 'writeoff';拜托各位了,我实在是没办法了。 定义:FUNCTION writeoff(acct_nbr:PChar; bill_charge:Integer; real_pay:Integer; flag:integer; staff_id:integer; staff_area_id:integer; aser_no:PChar; adate:PChar ):integer; stdcall; external 'a.dll' name 'writeoff';可能有问题;看来你在调用银行卡之类的东西的API;staff_id:integer; staff_area_id:integer;这两个中可能有个需要是返回的值;也就是需要VAR staff_area_id:integer 这个函数只返回是否成功,其他参数都是由我传入,不返回。这个a.dll在其他程序中也有使用,只不过是vc调用的,没有出现这种问题。我觉得是由于vc在分配内存时错误的使用了我在delphi中已经定义的变量所用的内存空间造成的,但我没有办法解决。 添加了var测试,仍然有错误。我用一个字符串保存了a,在a数据错误后使用字符串转回。间接解决了这个问题。但还是想知道原因。联系我请发邮件[email protected]。感谢各位的帮助。 窗体重载 Create方法的问题,帮帮忙 我们齐来抵制日本货! 请教一个小问题!!! 提问 : 用IDftp控件怎么取得当前下载和上传的进度呢? 请问怎么调试DLL中的代码啊??? 求救:怎么无法创建MDI窗体? Delphi里建备注字段怎么老出错? 怎么在Delphi里用ADO执行Oracle包里的存储过程并返回结果集?急急急急急急!!!! 使用QReport报表时的线宽问题 Windows下计算器中使用键盘输入时,屏幕上按键效果如何实现? delphi如何调用oracle的存储过程? 象QQ那样只要是链接地址的消息,就可以点击,是如何实现的?
………………
a:=func1(); //返回值为0(integer)
b:=func2(…………); //func2调用了vc的dll中的方法
showmessage(a); //在这里,a的值已经变成999
………………
end; function func2(acct_nbr:String; bill_charge:Integer; real_pay:Integer;
flag:integer; a_ser_no:String; a_date:String):Integer;
var
AdoRs: OleVariant;
acctNum:PChar;
billCharge:Integer;
realPay:Integer;
flagType:Integer;
staffId:Integer;
staffAreaId:Integer;
aSerNo:PChar;
aDate:PChar;
returnVal:Integer;
begin
AdoRS:=RunSql('select bt_staff_area_id, bt_staff_id ……'); GetMem(acctNum, 17); strpcopy(acctNum, acct_nbr);
aSerNo := PChar(a_ser_no);
aDate := PChar(a_date); billCharge:=bill_charge;
realPay:=real_pay;
flagType:=flag; staffId:=strToInt(trim(AdoRS.fields['bt_staff_id'].value));
staffAreaId:=strToInt(AdoRS.fields['bt_staff_area_id'].value); //*=999
if AdoRs.state<>stClosed then AdoRs.Close; returnVal:=writeoff(acctNum, billCharge, realPay,
flagType, staffId, staffAreaId, aSerNo, aDate);//vc的dll中的方法 if returnVal<>0 then
fucn2:=1 //返回值
else
func2:=0; freeMem(acctNum);
end;
end.定义:
FUNCTION writeoff(acct_nbr:PChar; bill_charge:Integer;
real_pay:Integer; flag:integer; staff_id:integer;
staff_area_id:integer; aser_no:PChar; adate:PChar ):integer;
stdcall; external 'a.dll' name 'writeoff';拜托各位了,我实在是没办法了。
FUNCTION writeoff(acct_nbr:PChar; bill_charge:Integer;
real_pay:Integer; flag:integer; staff_id:integer;
staff_area_id:integer; aser_no:PChar; adate:PChar ):integer;
stdcall; external 'a.dll' name 'writeoff';
可能有问题;
看来你在调用银行卡之类的东西的API;
staff_id:integer;
staff_area_id:integer;这两个中可能有个需要是返回的值;
也就是需要VAR staff_area_id:integer
这个a.dll在其他程序中也有使用,只不过是vc调用的,没有出现这种问题。
我觉得是由于vc在分配内存时错误的使用了我在delphi中已经定义的变量所用的内存空间造成的,但我没有办法解决。
我用一个字符串保存了a,在a数据错误后使用字符串转回。间接解决了这个问题。
但还是想知道原因。
联系我请发邮件[email protected]。
感谢各位的帮助。