动态链接库的动态加载问题

gxboy 2007-01-16 10:33:28
这个程序的样式和qq msn雷同,都是左边导航右边显示实际内容

现在我想在一个目录里存在动态链接库文件,这些文件里面包含程序的一些模块,比如象qq里 qq好友、移动硬盘,这些模块一样一个dll文件。

问题是dll文件数不定,即模块不定。所以在主程序启动时想遍历这个目录,把目录下的所有dll加入到程序中,然后把内容显示出来。当然所有dll都遵守统一的调用协议,比如所有的dll里都有一个XName作为界面导航的名称,ShowForm作为显示子窗体的名称。但声明api时都必须指定调用过程名称,而且这个名称不能动态创建,不知有没其它什么方法?



...全文
338 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlp555ren 2007-01-20
  • 打赏
  • 举报
回复
hongqi162(失踪的月亮)已经说得比较清楚了,你去看看一些关于动态加载DLL得例子,特别是调用带参数的函数的写法。。。
hongqi162 2007-01-17
  • 打赏
  • 举报
回复
While you can get the list of exported functions in a DLL, you cannot get the parameter list. To get this information, you would need get the documentation from the distributor of the DLL
hongqi162 2007-01-17
  • 打赏
  • 举报
回复
现在的问题怎样获得function 的parameters 也就是Parameters: array of Pointer这个参数
hongqi162 2007-01-17
  • 打赏
  • 举报
回复
function DynamicDllCallName(Dll: String; const Name: String; HasResult: Boolean; var Returned: Cardinal; const Parameters: array of Pointer): Boolean;
var
prc: Pointer;
x, n: Integer;
p: Pointer;
dllh: THandle;
begin
dllh := GetModuleHandle(PChar(Dll));
if dllh = 0 then begin
dllh := LoadLibrary(PChar(Dll));
end;
if dllh <> 0 then begin
prc := GetProcAddress(dllh, PChar(Name));
if Assigned(prc) then begin
n := High(Parameters);
if n > -1 then begin
x := n;
repeat
p := Parameters[x];
asm
PUSH p
end;
Dec(x);
until x = -1;
end;
asm
CALL prc
end;
if HasResult then begin
asm
MOV p, EAX
end;
Returned := Cardinal(p);
end else begin
Returned := 0;
end;
end else begin
Returned := 0;
end;
Result := Assigned(prc);
end else begin
Result := false;
end;
end;
zuoansuifeng 2007-01-17
  • 打赏
  • 举报
回复
在DLL中API也可以用的~~~
shadowstar 2007-01-16
  • 打赏
  • 举报
回复
方法有很多种,最主要的就是“都遵守统一的调用协议”。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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