第一次写这样的程序.打包成dll文件extern "C" _declspec(dllexport) BOOL WINAPI StartMaskKey()
{
MessageBoxW(NULL,NULL,L"1111",NULL);
hk=SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,NULL,0 );
MessageBoxW(NULL,(LPCWSTR)hk,L"1111",NULL);
return false;
/*
if(hk==NULL)
return false;
else
{
hk=SetWindowsHookEx(WH_KEYBOARD,LowLevelKeyboardProc,NULL,0 ); //如果换成WH_KEYBOARD_LL delphi调用会出现内存错误
return true;
}
*/
}#include "stdafx.h"
#include <iostream>
using namespace std;
DWORD dk[]={VK_NUMPAD0 ,VK_NUMPAD0 ,VK_NUMPAD0 };
int nlength=sizeof(dk)/sizeof(DWORD);
HHOOK hk=NULL;
BOOL CALLBACK KeyboardProc(WPARAM action, KBDLLHOOKSTRUCT* pKeyStruct)
{
switch (action)
{
case WM_KEYDOWN:
break;
case WM_KEYUP: break;
case WM_SYSKEYDOWN:
break;
case WM_SYSKEYUP:
break;
}
return false;
}
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBoxW(NULL,NULL,L"dfasd",NULL);
if(nCode>=HC_ACTION)
{
KBDLLHOOKSTRUCT* pStruct = (KBDLLHOOKSTRUCT*)lParam; //将lParam强制转换成KBDLLHOOKSTRUCT
for(int i=0;i<nlength;i++)
{
if(pStruct->vkCode==dk[i])
{
KeyboardProc(wParam,pStruct);
LPCWSTR c=(LPCWSTR)dk[i];
MessageBoxW(NULL,c,L"dfasd",NULL);
}
else
return CallNextHookEx(hk, nCode, wParam, lParam);
}
}
return CallNextHookEx(hk, nCode, wParam, lParam);;
}
{
MessageBoxW(NULL,NULL,L"1111",NULL);
hk=SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,NULL,0 );
MessageBoxW(NULL,(LPCWSTR)hk,L"1111",NULL);
return false;
/*
if(hk==NULL)
return false;
else
{
hk=SetWindowsHookEx(WH_KEYBOARD,LowLevelKeyboardProc,NULL,0 ); //如果换成WH_KEYBOARD_LL delphi调用会出现内存错误
return true;
}
*/
}#include "stdafx.h"
#include <iostream>
using namespace std;
DWORD dk[]={VK_NUMPAD0 ,VK_NUMPAD0 ,VK_NUMPAD0 };
int nlength=sizeof(dk)/sizeof(DWORD);
HHOOK hk=NULL;
BOOL CALLBACK KeyboardProc(WPARAM action, KBDLLHOOKSTRUCT* pKeyStruct)
{
switch (action)
{
case WM_KEYDOWN:
break;
case WM_KEYUP: break;
case WM_SYSKEYDOWN:
break;
case WM_SYSKEYUP:
break;
}
return false;
}
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBoxW(NULL,NULL,L"dfasd",NULL);
if(nCode>=HC_ACTION)
{
KBDLLHOOKSTRUCT* pStruct = (KBDLLHOOKSTRUCT*)lParam; //将lParam强制转换成KBDLLHOOKSTRUCT
for(int i=0;i<nlength;i++)
{
if(pStruct->vkCode==dk[i])
{
KeyboardProc(wParam,pStruct);
LPCWSTR c=(LPCWSTR)dk[i];
MessageBoxW(NULL,c,L"dfasd",NULL);
}
else
return CallNextHookEx(hk, nCode, wParam, lParam);
}
}
return CallNextHookEx(hk, nCode, wParam, lParam);;
}
==================
第三个参数用NULL当然不行了。
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process. 你玩DLL的,不能用NULL哦。。NULL只能用当前进程才必须设NULL.
填LoadLibrary获得的句柄