function GetModuleHandleFromInstance: THandle;
  var
    s: array[0..512] of char;
  begin
    GetModuleFileName(hInstance, s, sizeof(s)-1);
    Result := GetModuleHandle(s);
  end;调用的时候有两种
    一种是: SetWindowsHookEx(WH_mouse, HookHandler, HInstance, 0);  
    另一种是利用上面的函数 SetWindowsHookEx(WH_mouse, HookHandler, GetModuleHandleFromInstance, GetCurrentThreadID); 我想问问谁能帮我解释一下这段代码

解决方案 »

  1.   

    function GetModuleHandleFromInstance: THandle;   //取当前进程实例的模块句柄
      var
        s: array[0..512] of char;
      begin
        GetModuleFileName(hInstance, s, sizeof(s)-1);  //取当前实例的文件名
        Result := GetModuleHandle(s);                 //通过文件取得取模块句柄
      end;
    SetWindowsHookEx(WH_mouse, HookHandler, HInstance, 0);  
    or
    SetWindowsHookEx(WH_mouse, HookHandler, GetModuleHandleFromInstance, GetCurrentThreadID); //第三个参数是钩子处理函数所处模块的句柄;第四个参数是指定被监视的线程
    //如果第四个参数是 0 (NULL) (有时要钩子处理过程在DLL里面)则表示监视系统里面所有的进程结贴给分谢谢
      

  2.   

    我再问一个问题就给分
    我想知道的是这里面所说的“钩子处理函数所处模块的句柄”
    是否是指调用这个dll文件的那个应用程序的句柄呢?
      

  3.   

    是指这个 dll 的句柄
      

  4.   

    其实我不明白为什么不直接用handle而要费那么大劲用个函数来得到呢?