N
netbug
Unregistered / Unconfirmed
GUEST, unregistred user!
我想编写个对键盘的钩子函数:<br>我先编写了个DLL文件,请看:<br>这是cpp文件:<br>#include "windows.h"<br>HHOOK hhook;<br>LRESULT CALLBACK ProcKB(int nCode,WPARAM wParam,LPARAM lParam)<br>{<br> if(nCode<0)<br> return CallNextHookEx(hhook,nCode,wParam,lParam);<br> else<br> {<br> MessageBeep(7);<br> return CallNextHookEx(hhook,nCode,wParam,lParam);<br> }<br>}<br>这是def文件:<br>LIBRARY "bbDll"<br>EXPORTS<br>ProcKB<br>并编译成功且形成了bbDll.dll文件,我把此dll文件拷到以下文件所在的目录下。<br>接着我用MFC形成了个单文档文件的框架,我只在MainFrm.cpp文件添加了一些:<br>// CMainFrame<br>HHOOK hhook;<br>typedef LRESULT (*PROCKB)(int,WPARAM,LPARAM);<br>PROCKB hkprcXX;<br>HINSTANCE hinstDLL;<br>int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)<br>{ //原先的代码<br> // TODO: Delete these three lines if you don't want the toolbar to<br> // be dockable<br> hinstDLL=LoadLibrary("bbDll.dll");<br> hkprcXX=(PROCKB)GetProcAddress(hinstDLL,"ProcKB");<br> hhook=SetWindowsHookEx(WH_KEYBOARD,hkprcXX,hinstDLL,0);<br>//原先的代码<br>}<br>可在编译时,老是提示:<br>e:/Vc++/bbTest/MainFrm.cpp(79) : error C2664: 'SetWindowsHookExA' : cannot convert parameter 2 from 'long (__cdecl *)(int,unsigned int,long)' to 'long (__stdcall *)(int,unsigned int,long)'<br> This conversion requires a reinterpret_cast, a C-style cast or function-style cast<br>也就是hhook=SetWindowsHookEx(WH_KEYBOARD,hkprcXX,hinstDLL,0)错误,我不知错在哪?<br>请各位大虾帮助、指正,谢谢。<br>