⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 in_pu_dll.pas

📁 用Delphi实现Dll插件的方式
💻 PAS
字号:
unit In_Pu_Dll;
{版权所有 枫叶在线 HTTP://WWW.SKYGZ.COM SKYGZ@QQ.COM 风铃夜思雨}
interface

uses
  Windows, SysUtils, Controls, Classes, Forms,
  StdCtrls, Plugins;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ExeHandle: Hwnd;
  StrExePath: string;

function PluginInfo: PPluginInfo; cdecl; export;
function Getmodule: PPluginModule; cdecl;

function GetDllHandle(): Hwnd; cdecl;
function GetDllInstance(): THandle; cdecl;
function GetDllPath(): PChar; cdecl;
procedure SetExeInfo(This_Handle: Hwnd; This_ExePath: PChar); cdecl;
procedure SetAbout(This_Module: PPluginModule); cdecl;
procedure SetConfig(This_Module: PPluginModule); cdecl;
function Initialize(This_Module: PPluginModule): Integer; cdecl;
function Terminate(This_Module: PPluginModule): Integer; cdecl;
function Start(This_Module: PPluginModule): Integer; cdecl;
function Stop(This_Module: PPluginModule): Integer; cdecl;
implementation

{$R *.dfm}

const
  Ver = '1.00';

  Info: TPluginInfo = (
    Version: Ver;
    Description: 'TEST 插件';
    Module: Getmodule);

  DllModule: TPluginModule = (
    Description: '测试插件';
    DllHandle: GetDllHandle;
    DllInstance: GetDllInstance;
    DllPath: GetDllPath;
    ExeInfo: SetExeInfo;
    About: SetAbout;
    Config: SetConfig;
    Initialize: Initialize;
    Terminate: Terminate;
    Start: Start;
    Stop: Stop);

function PluginInfo: PPluginInfo;
begin
  result := @Info;
end;

function Getmodule: PPluginModule;
begin
  result := @DllModule;
end;

procedure SetExeInfo(This_Handle: Hwnd; This_ExePath: PChar);
begin
  ExeHandle := This_Handle;
  StrExePath := StrPas(This_ExePath);
end;

function GetDllHandle(): Hwnd;
begin
  result := application.Handle;
end;

function GetDllInstance(): THandle;
begin
  result := HInstance;
end;

function GetDllPath(): PChar;
var
  ModuleName: string;
begin
  SetLength(ModuleName, 260);
  GetModuleFileName(HInstance, PChar(ModuleName), Length(ModuleName));
  result := PChar(ModuleName);
end;

procedure SetAbout(This_Module: PPluginModule);
begin
  MessageBox(ExeHandle, '风铃夜思雨制作', 'About', MB_ICONINFORMATION);
end;

procedure SetConfig(This_Module: PPluginModule);
begin
  MessageBox(ExeHandle, '无配置', '配置', MB_ICONINFORMATION);
end;

function Initialize(This_Module: PPluginModule): Integer;
begin
  result := 1;
end;

function Terminate(This_Module: PPluginModule): Integer;
begin
  result := 1;
end;

function Start(This_Module: PPluginModule): Integer;
var
  R: TRect;
begin
  application.CreateForm(TForm1, Form1);
  if ExeHandle <> 0 then
  begin
    GetWindowRect(ExeHandle, R);
    Form1.left := R.left;
    Form1.top := R.Bottom;
    Form1.width := R.Right - R.left;
  end;
  Form1.show;
  Form1.Label1.Caption := StrExePath;
  Form1.Label2.Caption := GetDllPath;
  result := 1;
end;

function Stop(This_Module: PPluginModule): Integer;
begin
  Form1.Hide;
  Form1.free;
  result := 1;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  Form1.Hide;
  CanClose := false;
  Exit;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -