不是很难啊:
new->new wizard
dll文件代码:
library mydll;
{ 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;
procedure yourproc(参数);//与平常的一样
begin
end;
Exports
yourproc;
begin
end.
动态调用:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Tyourproc=procedure(filename,key
char);
stdcall;
//定义一个Tyourproc函数类.此处的stdcall参数不可少
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var // 动态调用
myproc:Tyourproc;
handle:Thandle;
begin
try
handle:=Loadlibrary('mydll.dll');
//加载trans_dll.dll
if handle<>0 then
begin
@myproc:=GetProcAddress(handle,'yourproc');
//找到trans_filename函数的入口地址
if @myproc<>nil then
begin
myproc(参数);
end;
end;
freeLibrary(handle);
//释放trans_dll.dll,一定要!
except
showmessage('ERROR!');
end;
end;
end.
DLL虽简单,却很麻烦!
有问题:major520@21cn.com