AfxGetInstanceHandle HINSTANCE AfxGetInstanceHandle( );Return ValueAn HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.ResThis function allows you to retrieve the instance handle of the current application. AfxGetInstanceHandle always returns the HINSTANCE of your executable file (.EXE) unless it is called from within a DLL linked with the USRDLL version of MFC. In this case, it returns an HINSTANCE to the DLL.
用AfxGetInstanceHandle
HINSTANCE AfxGetInstanceHandle( );
就可以。
就是包含HookProc的动态库加载地址。
否则给NULL就可以了
HINSTANCE AfxGetInstanceHandle( );Return ValueAn HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.ResThis function allows you to retrieve the instance handle of the current application. AfxGetInstanceHandle always returns the HINSTANCE of your executable file (.EXE) unless it is called from within a DLL linked with the USRDLL version of MFC. In this case, it returns an HINSTANCE to the DLL.
extern "C" __declspec(dllexport) BOOL starthook()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL bResult=FALSE;
glhHookKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,AfxGetInstanceHandle(),0);
if(glhHookKeyboard!=NULL)
bResult=TRUE;
return bResult;
}
其中AfxGetInstanceHandle()就可以得到这个dll的实例句柄,如楼上所所HINSTANCE AfxGetInstanceHandle( ); HINSTANCE也是一种句柄 就像常用的HWND一样 只是那时窗体句柄