怎样动态调用DLL?

regft 2006-01-18 05:09:51
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,
Classes,
forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
procedure LoadFormxp(AppHandle:THandle);stdcall;
begin
Application.Handle:=AppHandle;
Form1:=TForm1.Create(Application);
Form1.Show;
end;

procedure UnFormxp();stdcall;
begin
if Assigned(Form1) then
FreeAndNil(Form1);
end;
exports
LoadFormxp,
UnFormxp;

begin
end.


请大家帮助,怎样动态调用DLL?
...全文
176 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
regft 2006-01-21
  • 打赏
  • 举报
回复
有详细的吗?
zhangl_cn 2006-01-20
  • 打赏
  • 举报
回复
三个API函数:
LoadLibrary()
GetProcAddress()
FreeLibrary()
charles1975 2006-01-18
  • 打赏
  • 举报
回复
我也记不到了。给你个例子吧:
procedure test;
const
 ADllName='D:\dll\Project2.dll';
 AProcName='DoTest';
var
 Lib:Integer;
 AProc:procedure (H: THandle;AConn: TADOConnection); cdecl;
begin
try
  Lib:=LoadLibrary(PChar(ADllName));
  if Lib<>0 then
  try
   AProc:=GetProcAddress(Lib,PChar(AProcName));
   if @AProc=nil then
   begin
    MessageBox(Handle,Format('动态链接库"%s"中找不到过程"%s"的入口地址!',[ADllName,AProcName]),'错误','MB_ICONERROR);
    Exit;
   end;
   AProc(Application.Handle,ADOConnection1);
  finally
   FreeLibrary(Lib);
  end else
   MessageBox(Handle,Format('找不到动态链接库"%s"',[ADllName]),'错误',MB_ICONERROR);
 except
  on E:Exception do
  MessageBox(Handle,PChar('不明错误!错误信息为:'+E.Message),'错误',MB_ICONERROR);
 end;
end;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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