一个莫名其妙的错误
清钟沁桐 2008-10-25 02:55:28 #include <afxwin.h>
// #include <windows.h>
class CKeybHookApp : public CWinApp
{
public:
CKeybHookApp();
DECLARE_MESSAGE_MAP()
};
CKeybHookApp theApp;
LRESULT CALLBACK LaunchHook(int nCode,WPARAM wParam,LPARAM lParam);
HHOOK kbHook;
// #define pCW ((CWPSTRUCT*)lParam)
LRESULT CALLBACK LaunchHook(int nCode,WPARAM wParam,LPARAM lParam)
{
// 让其它全局钩子获得消息.
LRESULT Result=CallNextHookEx(kbHook,nCode,wParam,lParam);
//AfxMessageBox("LaunchHook");
if(nCode==HC_ACTION)
{
LPCTSTR info = NULL;
if( (lParam & WM_KEYDOWN) == WM_KEYDOWN)
{
info = "key dn";
}
else if( (lParam & WM_KEYUP) == WM_KEYUP)
{
info = "key up";
}
else if( (lParam & WM_SYSKEYDOWN) == WM_SYSKEYDOWN)
{
info = "sys key down";
}
else ( (lParam & WM_SYSKEYUP) == WM_SYSKEYUP )
{ // 41 行
info = "sys key up";
}
MessageBox(NULL,(LPCTSTR)info,"win",MB_OK)
} // 45 行
return Result;
}
int main (void)
{
kbHook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD,
(HOOKPROC)LaunchHook,
theApp.m_hInstance, 0 );
if( kbHook==NULL ) {
MessageBox(NULL,"error SetWindowsHookEx","win",MB_OK);
return 0;
}
// 消息循环是必须的,想知道原因可以查msdn
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
};
UnhookWindowsHookEx (kbHook);
return 0;
};
上面的程序编译运行时提示:
(41) : error C2143: syntax error : missing ';' before '{'
dd1.cpp(45) : error C2143: syntax error : missing ';' before '}'
但是这里明明 {} 已经配对了呀 ??