在线求助:wr传递字符串给delphi库函数
function msg(a:PChar):integer;begin
ShowMessage(string(a));
result:=0;
end;
--------------------------------------------
extern int msg(string);
load_dll("ttt.dll");
msg("ddd");
为什么不能正确显示? 传参数应该是没问题的,这段我没看懂,晕,没写过DLL 鼎鼎大名的生如火花 都不知道你谦虚了 WR中的变量没有类型,第2段你改成
extern a;
a="ddd"
load_dll("ttt.dll");
试试,不保证成功,不成功把extern换成static或者public再试试 斑竹,你肯定没在用winrunner吧 你问的这方面我的确水平不行,我是凭记忆写的,以前我应该是这样用的 load_dll("ttt.dll");
这一段没路径的能行么?没试过 动态库函数改成这样试试:
function msg(a:string):integer;
begin
showmessage(a);
Result :=0;
end; winterson
string肯定不行,会内存出错 哦,我实验一下,找到办法贴上来和大家分享 实验结果发现不是string参数的问题,而是showmessage的问题,它有用到vcl的机制,WR去调用的时候,没办法处理vcl发过来的消息,所以会死在那里;
以下实验:
function Inter(a:string):Integer;stdcall; //这里stdcall是有必要的;
begin
Result :=StrToInt(a);
end;
------------------------------------------------------------
extern int Inter(string);
load_dll("F:\\Loaddll\\dll\\project1.dll");
rc=Inter("123");
用watchlist可以看得到rc等于123,表示处理成功; 不知道楼主为什么会觉得function Msg(a:string):integer;会内存错误,请赐教! 问题解决办法找到:
直接用windowsAPI来提示,把showmessage函数改成messagebox函数就好了 winterson
你这样试过了可以?
我这里问题依旧... 没有问题:我把代码贴出来
--------------------------------------------
dll代码:
library Project1;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
windows,
Classes;
{$R *.res}
function ShowMessage(Msg:string):integer;stdcall;
begin
messagebox(0,PAnsiChar(Msg),'Say',0);
Result :=0;
end;
exports
ShowMessage;
begin
--------------------------------------------
--------------------------------------------
WR代码:
extern int ShowMessage(in string);
load_dll("H:\\Test\\project1.dll");
ShowMessage("Hello");
--------------------------------------------
没有问题 好,你的是对的,我的编程基础不够扎实,我少用了stdcall
页:
[1]