按键HOOK的问题
我用VC写了个监测键盘按键状态的HOOK,在VB里调用实现系统热键功能,但是用VB编译后在游戏里使用就出现有点卡的现象,这是为什么啊? 奇怪,既然能用VC,为什么要转回VB呢,VB对底层支持不太理想。 我自己直接用vb写的也没出现过卡的现象估计你hook程序没有写好 以下是我keybhook.DLL中的keybhook.CPP中的代码,编译后成keybhook.DLL在VB中调用就卡,为什么哦?
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include "keybhook.h"
HINSTANCE g_hinstDll = NULL;
#pragma data_seg(".drectve")
static char szLinkDirectiveShared[] = "-section:Shared,rws";
#pragma data_seg()
#pragma data_seg("Shared")
HHOOK g_hhook = NULL;
HWNDg_hwndPost= NULL;
UINTg_uMsgNotify = WM_USER;
#pragma data_seg()
static LRESULT WINAPI KeyboardHook_HookProc (int nCode,WPARAM wParam, LPARAM lParam)
{
LRESULT lResult = CallNextHookEx(g_hhook, nCode, wParam, lParam);
if (nCode == HC_ACTION)
{
PostMessage(g_hwndPost, g_uMsgNotify, wParam, lParam);
}
return(lResult);
}
BOOL WINAPI SetKeyboardHook (HWND hWndPost, UINT Msg)
{
HHOOK hhook;
if (g_hhook != NULL) return(FALSE);
g_hwndPost= hWndPost;
g_uMsgNotify = Msg;
Sleep(0);
hhook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHook_HookProc, g_hinstDll, 0);
InterlockedExchange((PLONG) &g_hhook, (LONG) hhook);
return(g_hhook != NULL);
}
BOOL WINAPI ReleaseKeyboardHook()
{
BOOL fOK = TRUE;
if (g_hhook != NULL)
{
fOK = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
return(fOK);
}
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hinstDll = hinstDll;
break;
}
return(TRUE);
}
页:
[1]