动态库
library tttd;
{...}
uses
Windows,
SysUtils,
Classes;
{$R *.res}
var
XXX : Integer;
procedure Init;
begin
XXX := $55AA55AA;
MessageBox(GetActiveWindow, PChar(IntToHex(XXX, 8)), 'Init', MB_OK);
end;
procedure DLLEntryPoint(dwReason: DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH: Init;
end;
end;
Exports
XXX ;
begin
@DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
主程序
unit ttt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
mh : THandle;
pX : PInteger;
begin
mh := LoadLibrary(PChar('TTTD.dll')) ;
if mh <> 0 then
begin
px := GetProcAddress(mh, 'XXX');
ShowMessage(IntToHex(px^, 8));
FreeLibrary(mh);
end;
end;
end.