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?

解决方案 »

  1.   

    我也记不到了。给你个例子吧:
    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;
      

  2.   

    三个API函数:
    LoadLibrary()
    GetProcAddress()
    FreeLibrary()