+ -
当前位置:首页 → 问答吧 → hook WM_CALLWNDPROC 后回调函数使用问题

hook WM_CALLWNDPROC 后回调函数使用问题

时间:2011-08-21

来源:互联网

我用下了个hook拦截WM_CALLWNDPROC消息,如果有新窗口创建的话,调用exe里面的一个回调参数,把新窗口的句柄传回exe中,并对新窗口进行操作,可是老会出现读取0x000000000的错误,各位大虾能不能告诉我到底怎么回事。感激不尽。

下面是部分代码;

//消息过滤函数

function CallWndProc(nCode: Integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var winStruct: TCWPStruct;
  wintitle:array[0..255] of char;
begin
  winStruct := PCWPSTRUCT(LParam)^;
  if nCode >= 0 then
  begin
  if winStruct.message = WM_CREATE then
  begin
  if getwindowtext(winStruct.hwnd,@wintitle,255)<>0 then
  begin
  cbfunc(winStruct.hwnd);//这个是回调函数,想用他传当前窗体的句柄给exe
  end;
  end;
  end;
  Result:= CallNextHookEx(0, nCode, WParam, LParam);
end;

//下钩子
procedure StartHook(cbfun:Tcbfunc); stdcall;
begin
  if PShare^.HookHandle = 0 then
  begin
  cbfunc:=cbfun;
  PShare^.HookHandle := SetWindowsHookEx(WH_CALLWNDPROC, PShare^.HookProc, HInstance, 0);
  end;
end;

作者: inkblot   发布时间: 2011-08-21

cbfun是exe中的,不会在其它进程当中,但是CallWndProc却是在其它进程运行的,因此不能执行cbfun

作者: Lactoferrin   发布时间: 2011-08-21

热门下载

更多