一般这个函数也是放在DLL中的,而回调函数一般也是放在同一个DLL中的,所以只要将DllMain中的hInstance保留下来传给它不就行了

解决方案 »

  1.   

    extern "C"  _declspec(dllimport) void _stdcall setHook();void CFindAndKillPorccessView::OnButtonHookAll() 
    {

    setHook();
    }//DLL
    //hook.h
    extern "C"  _declspec(dllexport) void _stdcall setHook();
    extern "C"  _declspec(dllexport) void _stdcall unHook();//hook.cpp
    #include "Hook.h"
    #include <windows.h>HHOOK hMouseHook;
    HHOOK hKeyHook;HINSTANCE hInstance;BOOL WINAPI DllMain(
      HINSTANCE hinstDLL,  // handle to the DLL module
      DWORD fdwReason,     // reason for calling function
      LPVOID lpvReserved   // reserved
      ){
    hInstance=hinstDLL;
    return true;
    };LRESULT CALLBACK MouseProc(
      int nCode,      // hook code
      WPARAM wParam,  // message identifier
      LPARAM lParam   // mouse coordinates
      ){
    return 1;
    }; void _stdcall setHook(){
    hMouseHook= SetWindowsHookEx(WH_MOUSE,MouseProc,hInstance,NULL);
    return;
    }
     void _stdcall unHook(){
      UnhookWindowsHookEx(hMouseHook);
     }