extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CQHOOK.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(CQhookDLL, hInstance))
return 0;
new CDynLinkLibrary(CQhookDLL);
glhInstance = hInstance;
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("CQHOOK.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(CQhookDLL);
}
return 1; // ok
}
调用程序的代码.
void CSimulateDlg::OnButton1()
{
// TODO: Add your control notification handler code here
if( !bSetup )
{
m_hook.Start();//激活全局钩子。
}
else
{
m_hook.Stop();//撤消全局钩子。
}
bSetup = !bSetup;
}