最近在帮老师做个小程序,本人是个大学生,是个菜鸟!
程序是一个监控程序,监控键盘信号(系统级别的),所以本人搞了个dll。
dll 部分代码:
extern "C" _declspec(dllexport) BOOL StartHook();
extern "C" _declspec(dllexport) BOOL StopHook();
BOOL CDLL008App::InitInstance()
{
// TODO: Add your specialized code here and/or call the base class
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hInstanceHandle = AfxGetInstanceHandle();
return CWinApp::InitInstance();
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LRESULT lRetVal;
lRetVal = CallNextHookEx(m_hHook, nCode, wParam, lParam);
if((lParam&0x80000000) && (HC_ACTION==nCode))
{
char c = (char)wParam;
CString strText;
strText.Format("您按了\"%c\"键", c);
AfxMessageBox(strText);
}
return lRetVal;
}
extern "C" _declspec(dllexport) BOOL StartHook()
{
m_hHook = (HHOOK)SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc, hInstanceHandle, 0);
return TRUE;
}
extern "C" _declspec(dllexport) BOOL StopHook()
{
if(m_hHook)
{
return UnhookWindowsHookEx(m_hHook);
}
return TRUE;
}
然后界面用c++ windows form做的(考虑过用mfc做,但是感觉forms更加直观)
但是在form里面调用dll怎么都搞不定~~~求老鸟帮忙,越详细越好~~谢谢
------解决方案--------------------------------------------------------
可以跟mfc一样
------解决方案--------------------------------------------------------
该回复于2012-02-11 19:58:32被版主删除