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

📄 unithookdll.pas

📁 Delphi写的屏幕取词程序
💻 PAS
字号:
unit UnitHookDLL;
interface
uses Windows, Messages, Dialogs, SysUtils;

  function OpenGetKeyHook(sender : HWND;MessageID : WORD) : BOOL; export;
  function CloseGetKeyHook: BOOL; export;

function LoadLibrary16(LibraryName: PChar): THandle; stdcall; external kernel32 index 35;
procedure FreeLibrary16(HInstance: THandle); stdcall; external kernel32 index 36;
function GetProcAddress16(Hinstance: THandle; ProcName: PChar): Pointer; stdcall; external kernel32 index 37;
procedure QT_Thunk; cdecl; external kernel32 name 'QT_Thunk';
var
  hInst16: THandle; {}
  pFuncCreate,pFuncFree: Pointer; {函数指针}
  MessageHook: THandle;
{ QT_Thunk 需要堆栈}
{$StackFrames On}


implementation

function SetGDIHook: boolean;
begin
  result:=false;
  if pFuncCreate = nil then exit;
  asm
     {保存寄存器的值}
      pushad
      push ebp
      sub esp,$2c
      mov edx, pFuncCreate{函数地址}
      mov ebp,esp
      add ebp,$2c
      call  QT_Thunk
      add esp,$2c
      pop ebp
      mov byte ptr result,al

      popad
  end;
end;

function UnSetGDIHook: boolean;
var
   reserve:array[0..$40] of char; //堆栈,一定要在最下!!!
begin
  result:=false;
  if pFuncCreate = nil then exit;
  asm
     {保存寄存器的值}
      pushad
      push ebp
      sub esp,$2c
      mov edx, pFuncFree{函数地址}
      mov ebp,esp
      add ebp,$2c
      call  QT_Thunk
      add esp,$2c
      pop ebp
      mov byte ptr result,al

      popad
  end;
end;

function GetMsgProc(code: integer; removal: integer; msg: integer): Integer; stdcall;
begin
  Result:=0;
end;

function OpenGetKeyHook(sender : HWND;MessageID : WORD) : BOOL; export;
begin
   MessageHook:=SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, HInstance, 0);
   SetGDIHook;
   result:=true;
end;

function CloseGetKeyHook: BOOL; export;
begin
   UnSetGDIHook;
   UnhookWindowsHookEx(MessageHook);   
   result:=true;   
end;

initialization
    pFuncFree:=nil;
    pFuncCreate:=nil;
    hInst16 := LoadLibrary16('project1.DLL');
    if hInst16 >= 32 then
    begin
       pFuncCreate := GetProcAddress16(hInst16, 'TextHookCreate');
       pFuncFree := GetProcAddress16(hInst16, 'TextHookFree');
       if (pFuncCreate=nil)or(pFuncFree=nil) then
       begin
          pFuncCreate:=nil;
          pFuncFree:=nil;
       end;
    end;
finalization
    if hInst16 >= 32 then
       FreeLibrary16(hInst16);

end.


⌨️ 快捷键说明

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