Ver Mensaje Individual
  #1  
Antiguo 09-01-2017
angelp4492 angelp4492 is offline
Miembro
 
Registrado: dic 2007
Posts: 99
Reputación: 0
angelp4492 cantidad desconocida en este momento
SetWindowsHookEx

Hola, como están.

Estoy intentado hacer un hook al mouse tengo una dll con el siguiente code.
Código Delphi [-]
library hook;


uses
  Windows,
  Messages,
  sysutils,
  dialogs;
const
      WH_MOUSE_LL = 14;
      var
      HookHandle: Cardinal;
   

 
{$R *.res}

function StopMouseHook: Boolean;stdcall;
begin
  UnhookWindowsHookEx(HookHandle);
  if HookHandle = 0 then
    Result := False
  else
   Result := True;
end;

function LowLevelMouseProc(nCode: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
Type
  tagMSLLHOOKSTRUCT = record
    POINT: TPoint;
    mouseData: DWORD;
    flags: DWORD;
    time: DWORD;
    dwExtraInfo: DWORD;
  end;
  TMSLLHOOKSTRUCT = tagMSLLHOOKSTRUCT;
  PMSLLHOOKSTRUCT = ^TMSLLHOOKSTRUCT;
var
 Delta:Smallint;
 posx:Integer;
 posy:integer;
begin
   
  if (nCode >= 0) then
  begin
   
    if wParam = WM_LButtonDOWN then
    begin
           
           //hacer lo que queramos al detectar.
            showmessage('Me has pulsado');
    end;
  end;
  Result := CallNextHookEx(HookHandle, nCode, wParam, lParam);
end;

function startMouseHook: Boolean;stdcall;
 var
   msg:TMsg;
begin
  Result := false;
  if HookHandle = 0 then
  begin
     HookHandle := SetWindowsHookExW(WH_MOUSE_LL, @LowLevelMouseProc, HInstance, 0);
     Result := HookHandle <> 0;
  end;
end;

procedure DLLEntryPoint(dwReasonWORD);
begin
  case dwReason of
    DLL_PROCESS_ATTACH:
    begin

      startMouseHook;

     
    end;
    DLL_PROCESS_DETACH:
    begin

       StopMouseHook;
      
    end;

    end;
end;



begin
   DllProc:=@DLLEntryPoint;
  DLLEntryPoint(DLL_PROCESS_ATTACH);
end.

Esta dll si la cargo normal funciona bien, pero por el contrario si la inyecto en un proceso no me funciona. La inyección se realiza por que lo he comprobado por medio de un messagebox, he leido que SetwindowsHookex no funciona desde una dll inyectada. alguien a tenido el mismo problema.

Última edición por angelp4492 fecha: 09-01-2017 a las 18:44:16.
Responder Con Cita