/////////dll1.dpr //////////////////
library dll1;
uses
SysUtils,dialogs,
Classes;
function f1(n:string):string;stdcall;
begin
result:=n;
end;
procedure p1(s:string);stdcall;
begin
showmessage(s);
end;
exports
f1,p1;
{$R *.res}
begin
end.
/////////////////////Unit1.pas////////////////////
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
gdi32='dll1.dll';
function f1(n:string):string;stdcall;external gdi32 ;
procedure p1(n:string);stdcall;external gdi32;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
caption :=f1(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
p1('sssss');
end;
procedure TForm1.Button3Click(Sender: TObject);
type
tf2=function(n:string):string;
var
i:integer;
handle:thandle;
f2:tf2;
begin
handle:=loadlibrary('dll1.dll');
if handle>32 then
f2:=getprocaddress(handle,'f1');
caption:=f1(Edit1.Text);
freelibrary(handle);
end;
end.
////////////////////////Unit1.dfm//////////////////////
object Form1: TForm1
Left = 225
Top = 279
Width = 423
Height = 168
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 24
Top = 80
Width = 113
Height = 25
Caption = #38745#24577#35843#29992#20989#25968
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 32
Top = 24
Width = 121
Height = 21
ImeName = #20013#25991' ('#31616#20307') - '#26234#33021' ABC'
TabOrder = 1
Text = '2'
end
object Button2: TButton
Left = 152
Top = 80
Width = 113
Height = 25
Caption = #38745#24577#35843#29992#36807#31243
TabOrder = 2
OnClick = Button2Click
end
object Button3: TButton
Left = 280
Top = 80
Width = 113
Height = 25
Caption = #21160#24577#35843#29992#20989#25968
TabOrder = 3
OnClick = Button3Click
end
end
///////////Project1.dpr///////////
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
静态调用和动态调用的例子都在里面了 如果还不明白 加我QQ 55423726 我把自己当时自学的这个传给你