|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 qq502984975 于 2013-5-16 23:48 编辑
源码如下:
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;
{$R *.res}
function test(x,y:Integer):Integer ; stdcall;
begin
Result:=x+y;
end;
exports
test;
begin
end.
------------------------------------------------------------------------------------------------------------------------------------
unit dll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Tdlltest=function (x,y:Integer):Integer;stdcall;
var
Form1: TForm1;
implementation
{$R *.dfm}
//function test(x,y:Integer):Integer;stdcall;external'mydll.dll';
procedure TForm1.btn1Click(Sender: TObject);
var
dllHandle:THandle;
test:TdllTest;
begin
//ShowMessage('111111');
dllHandle:=LoadLibrary('mydll.dll');
GetProcAddress(dllHandle,'test');
edt1.Text:=IntToStr(test(2,2));
FreeLibrary(dllHandle);
{n:=test(3,9) ;
ShowMessage(IntToStr(n)); }
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
Close;
end;
end.
----------------------------------------------------------------------------------------------------------------------------------------------------
|
-
-
|