Noob23
      
Beiträge: 93
Win XP, Win Server 2003, Win 7, Ubuntu
Delphi 7, c/c++ Dev-c++, µC-8051 Keil, Webdesign Notepad++
|
Verfasst: Mi 23.08.06 08:42
guten morgen zusammen,
kann mir jemand helfen informationen via fensternachrichten von einer ".dll" in meine anwendung zu schieben?
theorie: in der ".dll" steht ein globaler tastatur-hook, der wenn eine bestimmte taste gedrückt wird eine procedure in der anwendung starten soll.
DLL
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
| library hook_board;
uses Windows, Messages;
var HookHandle: Cardinal = 0; WindowHandle: Cardinal = 0;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); case nCode < 0 of TRUE: exit; FALSE: begin SendMessage(HWND_BROADCAST, nCode, wParam, lParam); end; end; end;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall; begin Result := False; if HookHandle = 0 then begin HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0); WindowHandle := Hwnd; Result := TRUE; end; end;
function UninstallHook: Boolean; stdcall; begin Result := UnhookWindowsHookEx(HookHandle); HookHandle := 0; end;
exports InstallHook, UninstallHook; end. |
form
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114:
| unit form1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ScktComp, StdCtrls, Spin, ExtCtrls;
type Thaupt = class(TForm) clients: TListBox; server: TServerSocket; start_stop: TButton; button_end: TButton; spin_port: TSpinEdit; Button1: TButton; Panel1: TPanel; procedure FormDestroy(Sender: TObject); procedure DeleteClient(Socket: TCustomWinSocket); procedure ClientSend(const Text: String); procedure serverClientConnect(Sender: TObject; Socket: TCustomWinSocket); procedure serverClientDisconnect(Sender: TObject; Socket: TCustomWinSocket); procedure serverClientError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); procedure start_stopClick(Sender: TObject); procedure button_endClick(Sender: TObject); private public procedure wmuser(var HWND_BROADCAST : hwnd); end;
var haupt: Thaupt;
function InstallHook(Hwnd: Cardinal): Boolean; stdcall; external 'hook_board.dll'; function UninstallHook: Boolean; stdcall; external 'hook_board.dll';
implementation
{$R *.dfm}
procedure Thaupt.FormDestroy(Sender: TObject); begin if (server.Active) then server.Close; end;
procedure Thaupt.button_endClick(Sender: TObject); begin Close; end;
procedure Thaupt.serverClientConnect(Sender: TObject; Socket: TCustomWinSocket); begin clients.AddItem(Socket.ReceiveText,Socket); end;
procedure Thaupt.DeleteClient(Socket: TCustomWinSocket); var i : Integer; begin i := clients.Items.IndexOfObject(Socket); if (i > -1) then clients.Items.Delete(i); end;
procedure Thaupt.serverClientDisconnect(Sender: TObject; Socket: TCustomWinSocket); begin DeleteClient(Socket); end;
procedure Thaupt.serverClientError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); begin if (Socket.Connected) then Socket.Close; DeleteClient(Socket); ErrorCode := 0; end;
procedure Thaupt.ClientSend(const Text: String); var i : Integer; begin for i := 0 to clients.Count-1 do (clients.Items.Objects[i] as TCustomWinSocket).SendText(Text); end;
procedure Thaupt.start_stopClick(Sender: TObject); begin if start_stop.Caption = 'Run' then begin start_stop.Caption := 'Stop'; spin_port.Enabled := false; button_end.Enabled := false; server.Port := spin_port.Value; server.Open; InstallHook(1); end else begin clients.Clear; start_stop.Caption := 'Run'; spin_port.Enabled := true; button_end.Enabled := true; if (server.Active) then server.Close; UninstallHook; end; end;
procedure Thaupt.wmuser(var HWND_BROADCAST : hwnd); begin panel1.Color := clRed end;
end. |
vielen dank im vorraus 
|