[Delphi] SetWindowsHookEx InjectLIB

On viernes, 28 de enero de 2011 0 comentarios

Well i started browsing the net for tutorials and found this web:

http://www.edgeofnowhere.cc/viewtopic.php?p=2483118

In there they explain a way to inject a dll via SetWindowsHookEx

So far so good, i started translating it from C++ to Delphi

Here is what i have:


Code:
var
  Form1: TForm1;
  dllhandle:thandle;

implementation

{$R *.dfm}


function CBTProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): dword; stdcall;
begin
dllhandle:=LoadLibrary('C:\injected.dll');
result:=CallNextHookEx(0,nCode,WPARAM,LPARAM);
end;

procedure InjectDLL({dllname:pchar;}windowname:pchar);
var
cb_proc_offset,pid:dword;
begin
pointer(cb_proc_offset):=@CBTProc;
SetWindowsHookEx(WH_CBT,@cb_proc_offset,dllhandle,getwindowthreadprocessid(findwindow(nil,pchar(windowname)),@pid));
showmessage(inttohex(dllhandle,1));
end;



Return value of dllhandle is 0 and no dll is injected at all, how can i fix that?

0 comentarios:

Publicar un comentario