你不给Threadid赋值,它一直是0,然后你就把它传入函数里了??????
Threadid =AppDomain.GetCurrentThreadId()这是获取当前线程的句柄
如果你要获取的不是当前线程,那至少你要告诉编译器你到底要获取的是哪个线程的句柄啊,而不是传入个0拉倒
否则鬼知道你到底想对谁使用钩子

解决方案 »

  1.   

    Threadid = WindowsAPI.GetWindowThreadProcessId(WindowsAPI.FindWindow(null, wTitleName),ref Processid);
    不是赋值?
      

  2.   

    并且Threadid 我看到是有值的
      

  3.   

    WindowsAPI.FindWindow(null, wTitleName),把这句分开执行,看句柄对不对,给其它进程装钩子,回调函数要在dll内
      

  4.   

    我的回调函数是在dll内,但是dll在主程序中直接引用进来就行了吧?
      

  5.   

    pInstance 这个参数传入IntPtr.Zero。除非你使用全局勾子才有传值进去。不过你使用全局勾子这参数又错了,这个得用标准DLL的Instance
    看MSDN的描述,似乎楼主这方法无解。
    hMod [in]
    Type: HINSTANCEA handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process. 用VC做一个DLL吧。使用全局勾子或是注入 
      

  6.   

    戳我c# 使用hook来监控鼠标键盘事件的示例代码