15,471
社区成员
发帖
与我相关
我的任务
分享
// CBT.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#define CBTHOOKLIB extern "C" __declspec(dllexport)
#include "CBT.h"
#pragma data_seg("CBTHOOK")
HHOOK g_hHook=NULL;
#pragma data_seg()
#pragma comment(linker,"/Section:CBTHOOK,RWS")
HINSTANCE g_hinstance;
BOOL APIENTRY DllMain( HINSTANCE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hinstance = hModule;
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
LRESULT CALLBACK CBTProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(nCode == HCBT_ACTIVATE)
{
}
return(CallNextHookEx(g_hHook, nCode, wParam, lParam));
}
BOOL WINAPI CBT_HookAllApps(BOOL bInstall)
{
BOOL bOk;
if (bInstall) {
//ASSERT(g_hHook == NULL); // Illegal to install twice in a row
// Install the Windows' hook
g_hHook = SetWindowsHookEx(WH_CBT, CBTProc,
g_hinstance, 0);
bOk = (g_hHook != NULL);
} else {
// Can't uninstall if not installed
BOOL bResult=FALSE;
if(g_hHook)
{
bResult= UnhookWindowsHookEx(g_hHook);
if(bResult)
g_hHook=NULL;
}
}
return(bOk);
}