看看这函数怎么调?我搞了好久,请高手帮忙,关于DLL函数的调用。

mgqmgq 2005-08-04 11:03:06
VC中的声明
int ReadSrvReq(char* ctrlMsg, char* subCode,
char* contentMsg, int* msgLen,
int timeOut)
DELPHI中声明:
TReadSrvReq=function(ctrlMsg:Pchar;subCode:Pchar;contentMsg:Pchar; msgLen:integer;timeOut:integer):integer;stdcall;
调用:
mw:HWND;
mt:TCSGP_ReadConf;
mt1: TReadSrvReq;
a:integer;
st:string;
p:pchar;
ctrlMsg:string;
subCode:string;
contentMsg:string;
msgLen:integer;
time1:String;
mw:=loadlibrary('CSGPAPI_DLL.dll');
if mw<>0 then
try
mt1:=GetProcaddress(mw,'ReadSrvReq');

if assigned(mt1) then
a:=mt1(@ctrlMsg,@subCode,@contentMsg, msgLen,5);

finally
FreeLibrary(mw);
end;
到了这步a:=mt1(@ctrlMsg,@subCode,@contentMsg, msgLen,5);就出错了。

请问DLL函数应怎么声明,参数怎么传呢?
...全文
141 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovefox_zoe 2005-08-04
  • 打赏
  • 举报
回复
楼上?不会吧。应该用pchar类型吧。
Bluce4587 2005-08-04
  • 打赏
  • 举报
回复
指针类型的参数,在DELPHI中要声明为 wideString 类型
mgqmgq 2005-08-04
  • 打赏
  • 举报
回复
ctrlMsg,subCode,contentMsg为出参; msgLen为入参出参。
mgqmgq 2005-08-04
  • 打赏
  • 举报
回复
别关注啊,出了主意了。
hqhhh 2005-08-04
  • 打赏
  • 举报
回复
关注:
LocustWei 2005-08-04
  • 打赏
  • 举报
回复
TReadSrvReq=function(ctrlMsg:Pchar;subCode:Pchar;contentMsg:Pchar; var msgLen:integer;timeOut:integer):integer;stdcall;

mt1(pchar(ctrlMsg),PChar(subCode),PChar(contentMsg), IntPnt,5);//
小呆之家 2005-08-04
  • 打赏
  • 举报
回复
try
mt1:=GetProcaddress(mw,'ReadSrvReq');
IntPnt:=@msglen;//----这里有点错误,改正下。:)
if assigned(mt1) then
广州接入 2005-08-04
  • 打赏
  • 举报
回复
mark
小呆之家 2005-08-04
  • 打赏
  • 举报
回复
VC中的声明
int ReadSrvReq(char* ctrlMsg, char* subCode,
char* contentMsg, int* msgLen,
int timeOut)
DELPHI中声明:
type
PInt=^integer;
TReadSrvReq=function(ctrlMsg:Pchar;subCode:Pchar;contentMsg:Pchar; msgLen:Pint;timeOut:integer):integer;stdcall;
调用:
mw:HWND;
mt:TCSGP_ReadConf;
mt1: TReadSrvReq;
a:integer;
st:string;
p:pchar;
ctrlMsg:string;
subCode:string;
contentMsg:string;
msgLen:integer;
IntPnt:Pint;//----------add
time1:String;

mw:=loadlibrary('CSGPAPI_DLL.dll');
if mw<>0 then
try
mt1:=GetProcaddress(mw,'ReadSrvReq');
IntPnt:=^msglen;//---------add
if assigned(mt1) then

a:=mt1(@ctrlMsg,@subCode,@contentMsg, IntPnt,5);//------add

finally
FreeLibrary(mw);
end;
//-----这样试试看吧 :)

mgqmgq 2005-08-04
  • 打赏
  • 举报
回复
件PCHAR是对的。
但不明白为什么,调用时就出错。

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧