Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi AV bei MausHook (https://www.delphipraxis.net/39417-av-bei-maushook.html)

perle 2. Feb 2005 13:12


AV bei MausHook
 
Hallo zusammen, ich wollte einen Maushook schreiben, der eine Message an mein Programm schickt , wenn die Linke Maustaste gedrückt wurde (macht nicht viel Sinn, ist auch nur zu Testzwecken). Ich habe also folgendes zusammengebastelt :

Delphi-Quellcode:
library hookdll;

uses
  madExcept,
  madLinkDisAsm,
  SysUtils,
  Dialogs,
  windows,
  messages,
  Classes;

var
  HookHandle : Cardinal;
  ProgHwnd  : Cardinal;

{$R *.res}

function mouseproc(ncode : Integer; wp : WPARAM; lp : LPARAM) : LRESULT ; stdcall;
begin
  result := CallNextHookEx(HookHandle,ncode,wp,lp);
  if (nCode = HC_ACTION) and (wp = WM_LBUTTONDOWN) then
  begin
    cds.dwData := wp;
    cds.cbData := 0;
    cds.lpData := nil;
    SendMessage(ProgHwnd,WM_COPYDATA,LongInt(HookHandle),LongInt(@cds));
  end;
end;

function InstallHook(aHandle : Cardinal) : BOOL; stdcall;
begin
    ProgHwnd  := aHandle;
    HookHandle := SetWindowsHookEx(WH_MOUSE,@mouseproc,HInstance,0);
    if HookHandle <> 0 then
        result := TRUE
    else result := FALSE;
end;

function UninstallHook : BOOL; stdcall;
begin
    result := UnhookWindowsHookEx(HookHandle);
end;

exports
    InstallHook,
    UninstallHook;
begin
end.
ist das überhaupt bis hier hin richtig?
Naja, jedenfalls rufe ich die Installfunktion dann im Hauptprogramm mit
Delphi-Quellcode:
if InstallHook(handle) then showmessage('installiert');
auf, das wird auch ausgeführt, die message wird ausgegeben, und schwupps , gibts ne Zugriffsverletzung. Weiss jemand warum das so ist?

Olli 1. Jul 2005 13:19

Re: AV bei MausHook
 
Ich würde dir erstmal empfehlen die ganzen Units aus USES zu entfernen (außer Windows und Messages). Teste dann nochmal.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:18 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz