hi peanut danke für deine antwort,
also ich habe jetzt folgednes schonmal gemacht:
Dll:
Delphi-Quellcode:
library
WndMsgSniffer;
uses
Windows,
Messages;
Type
tag =
record
LPARAM :lParam;
WPARAM :wParam;
message:Cardinal;
HWND :hwnd;
end;
PMsg = ^Tag;
var
HookHandle :Cardinal;
TargetWindowHandle:Cardinal;
OwnWindowHandle :Cardinal;
function GetMsgProc(code: integer; wParam: WPARAM; lParam: LPARAM): LResult;
stdcall;
var
var aCopy:TCopyDataStruct;
begin
if (code < 0)
Then
exit
else
begin
{IPC zeugs}
with aCopy
do
begin
dwData := PMsg(lparam).
Message
cbData := 0;
lpData :=
nil;
end;
SendMessage(ApplicationHandle, WM_COPYDATA, Longint(HookHandle),LongInt(@aCopy));
end;
Result := CallNextHookEx(HookHandle, Code, wparam, lparam);
end;
function InstallHooks(Hwnd: Cardinal;OwnHwnd:Cardinal): Boolean;
stdcall;
begin
TargetWindowHandle:=Hwnd;
//Handle des zu schützenden Fensters
OwnWindowHandle:=OwnHwnd;
//Handle des Hauptprogramm-Fensters
HookHandle := SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hinstance, GetWindowThreadProcessId(TargetWindowHandle));
Result:=Hookhandle<>0;
end;
function UninstallHooks: Boolean;
stdcall;
begin
result:=UnHookWindowsHookEx(HookHandle);
end;
exports
InstallHooks,
UninstallHooks;
begin
end.
Hauptfenster:
Delphi-Quellcode:
[...]
private
procedure HandleMessage(
var Message: TWMCopyData);
[...]
var
Form1: TForm1;
implementation
function InstallHooks(Hwnd: THandle;OwnHwnd:Cardinal): Boolean;
stdcall;
external '
WndMsgSniffer.dll';
function UninstallHooks: Boolean;
stdcall;
external '
WndMsgSniffer.dll';
{$R *.dfm}
//ipc nachrichten empfangen
procedure TForm1.HandleMessage(
var Message: TWMCopyData);
begin
listbox1.items.add(IntToStr(
Message.CopyDataStruct.dwData));
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Targethandle: Thandle;
begin
//nur zum testen
Targethandle:= FindWindow(PChar('
Notepad'),PChar('
Unbenannt - editor'));
SetForegroundWindow(targethandle);
if InstallHooks(Targethandle,application.handle)
then //Hooks installieren.
ShowMessage('
Installed Successfully.');
end;
Nur leider funzt es nicht,
in der listbox wird leider reingarnix eingetragen, nein ich bekomme selbst nicht mal die "Installed Successfully" nachricht.
bin jetzt verzeifelt.........was habe ich falsch gemacht??
danke für weitere antworten.