2. Code from the calling Program
{this program get's the Char from the DLL in 2 ways,
as a Char message to a Memo and as a DLLMessage WM_USER+1678}
Code: |
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) but_StartHook: TButton; but_StopHook: TButton; label1: TLabel; Memo1: TMemo; procedure but_StartHookClick(Sender: TObject); procedure but_StopHookClick(Sender: TObject); private { Private declarations } hLib2: THandle; DllStr1: string; procedure DllMessage(var Msg: TMessage); message WM_USER + 1678; public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DllMessage(var Msg: TMessage); begin if (Msg.wParam = 8) or (Msg.wParam = 13) then Exit; {the 8 is the Backspace and the 13 if the Enter key, You'll need to do some special handleing for a string} DllStr1 := DllStr1 + Chr(Msg.wParam); label1.Caption := DllStr1; end;
procedure TForm1.but_StartHookClick(Sender: TObject); type TStartHook = function(MemoHandle, AppHandle: HWND): Byte; var StartHook1: TStartHook; SHresult: Byte; begin hLib2 := LoadLibrary('HookLib.dll'); @StartHook1 := GetProcAddress(hLib2, 'StartHook'); if @StartHook1 = nil then Exit; SHresult := StartHook1(Memo1.Handle, Handle); if SHresult = 0 then ShowMessage('the Key Hook was Started, good'); if SHresult = 1 then ShowMessage('the Key Hook was already Started'); if SHresult = 2 then ShowMessage('the Key Hook can NOT be Started, bad'); if SHresult = 4 then ShowMessage('MemoHandle is incorrect'); end;
procedure TForm1.but_StopHookClick(Sender: TObject); type TStopHook = function: Boolean; var StopHook1: TStopHook; hLib21: THandle; begin @StopHook1 := GetProcAddress(hLib2, 'StopHook'); if @StopHook1 = nil then begin ShowMessage('Stop Hook DLL Mem Addy not found'); Exit; end; if StopHook1 then ShowMessage('Hook was stoped'); FreeLibrary(hLib2); {for some reason in Win XP you need to call FreeLibrary twice maybe because you get 2 functions from the DLL? ?} FreeLibrary(hLib2); end;
end. |
- << Назад
- Вперёд
Просьба писать ваши замечания, наблюдения и все остальное,
что поможет улучшить предоставляемую информацию на этом сайте.
ВСЕ КОММЕНТАРИИ МОДЕРИРУЮТСЯ ВРУЧНУЮ, ТАК ЧТО СПАМИТЬ БЕСПОЛЕЗНО!