1,183
社区成员
发帖
与我相关
我的任务
分享
library DllEntry;
uses
System.SysUtils,
System.Classes,
Winapi.Windows,
Vcl.Dialogs;
{$R *.res}
procedure DLLEntryPoint(dwreason:DWord);
begin
case dwReason of
DLL_PROCESS_ATTACH: showmessage('Attaching to process');
DLL_PROCESS_DETACH :showmessage('Detaching from process');
DLL_THREAD_ATTACH : MessageBeep(0);
DLL_THREAD_DETACH : MessageBeep(0);
end;
end;
begin
DllProc :=@DLLEntryPoint;
DllEntryPoint(Dll_PROCESS_ATTACH);
end.
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
LibHandle : THandle;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if LibHandle = 0 then
begin
LibHandle := LoadLibrary('DllEntry.dll');
if LibHandle =0 then
raise Exception.Create('Unable to load Dll');
end
else
MessageDlg('Library already loaded' ,mtWarning,[mbOK],0);
end;
end.