Einzelnen Beitrag anzeigen

neolithos

Registriert seit: 31. Jul 2003
Ort: Dresden
1.386 Beiträge
 
Delphi 7 Architect
 
#23

Re: Problem mit Nachricht aus DLL

  Alt 7. Jul 2004, 13:52
Zum Registrieren:

Delphi-Quellcode:
var hMap : Cardinal = 0;
    hLib : Cardinal = 0;

procedure RegisterMouseHook(hWnd, wmNotify : Cardinal);
var pData : PHookData;
    proc : Pointer;
begin
  if hMap = 0 then
     try
       hLib := LoadLibrary('Hk.dll');
       if hLib = 0 then
          raise Exception.Create('Hk.dll nicht gefunden.');

       proc := GetProcAddress(hLib, 'MouseHook');
       if proc = nil then
          raise Exception.Create('Hook-Procedure nicht gefunden.');

       hMap := CreateFileMapping(0, nil, PAGE_READWRITE, 0, SizeOf(THookData), csFileMappingMouse);
       if hMap = 0 then
          raise Exception.Create('Filemapping fehlgeschlagen');

       pData := MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
       pData^.hWnd := hWnd;
       pData^.wmNotify := wmNotify;
       pData^.hk := SetWindowsHookEx(WH_MOUSE, proc, hLib, 0);
       if pData^.hk = 0 then
          raise Exception.Create('Hook konnte nicht installiert werden.');

       UnmapViewOfFile(pData);
     except
       FreeLibrary(hLib);
       CloseHandle(hMap);
       raise;
     end;
end;

procedure UnRegisterMouseHook;
var pData : PHookData;
begin
  if hMap <> 0 then
     begin
       pData := MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
       UnhookWindowsHookEx(pData^.hk);
       UnmapViewOfFile(pData);
       FreeLibrary(hLib);
       CloseHandle(hMap);
       hMap := 0;
     end;
end;
- ciao neo -
Es gibt niemals dumme Fragen, sondern nur dumme Antworten!
  Mit Zitat antworten Zitat