问题描述
- 新手MFC求助,关于error LNK2019的问题。
-
1>MFCApplication2Dlg.obj : error LNK2019: 无法解析的外部符号 "public: static long __stdcall CMFCApplication2Dlg::JournalRecordProc(int,unsigned int,long)" (?JournalRecordProc@CMFCApplication2Dlg@@SGJHIJ@Z),该符号在函数 "public: void __thiscall CMFCApplication2Dlg::OnBnClickedButton3(void)" (?OnBnClickedButton3@CMFCApplication2Dlg@@QAEXXZ) 中被引用
1>MFCApplication2Dlg.obj : error LNK2019: 无法解析的外部符号 "public: static long __stdcall CMFCApplication2Dlg::JounralPlaybackProc(int,unsigned int,long)" (?JounralPlaybackProc@CMFCApplication2Dlg@@SGJHIJ@Z),该符号在函数 "public: void __thiscall CMFCApplication2Dlg::OnBnClickedButton1(void)" (?OnBnClickedButton1@CMFCApplication2Dlg@@QAEXXZ) 中被引用
1>E:PJBMFCApplication2DebugMFCApplication2.exe : fatal error LNK1120: 2 个无法解析的外部命令
void CMFCApplication2Dlg::OnBnClickedButton3()
{
hHook =SetWindowsHookEx(
WH_JOURNALRECORD,
(HOOKPROC)JournalRecordProc,
AfxGetApp()->m_hInstance,
0
);// TODO: 在此添加控件通知处理程序代码
}
void CMFCApplication2Dlg::OnBnClickedButton1()
{
hHook=SetWindowsHookEx(
WH_JOURNALPLAYBACK,
(HOOKPROC)JounralPlaybackProc,
AfxGetApp()->m_hInstance,
0
);
// TODO: 在此添加控件通知处理程序代码
}
static LRESULT CALLBACK JournalRecordProc(int nCode,WPARAM wparam,LPARAM lparam)
{
if (nCode<0)
return CallNextHookEx(NULL,nCode,wparam,lparam);
EVENTMSG*pmsg=(EVENTMSG*)lparam;
switch(nCode)
{
case HC_ACTION:
{EVENTMSG * pEventMsg =new EVENTMSG;
memcpy(pEventMsg,pmsg,sizeof(EVENTMSG));
EventMsgList.AddTail(pEventMsg);}
break;
case HC_SYSMODALOFF:
break;
case HC_SYSMODALON:
break;}
}
static LRESULT CALLBACK JournalPlaybackProc(int nCode,WPARAM wparam,LPARAM lparam)
{
static unsigned i=0;
static BOOL bFlag =TRUE;
EVENTMSG*pMsg;
POSITION pos;
DWORD PreTime,NowTime;
switch (nCode)
{
case HC_SKIP:
bFlag =TRUE;
i++;
break;
case HC_GETNEXT:
if(i>=EventMsgList.GetCount()-2)
{
i=0;
UnhookWindowsHookEx(hHook);
AfxMessageBox(_T("回放完毕!"));
}
pos=EventMsgList.FindIndex(i);
pMsg=EventMsgList.GetAt(pos);
memcpy((LPEVENTMSG)lparam,pMsg,sizeof(EVENTMSG));
if((i)!=0 && bFlag==TRUE)
{
bFlag=FALSE;
NowTime=pMsg->time;
pos=EventMsgList.FindIndex(i-1);
pMsg=EventMsgList.GetAt(pos);
PreTime=pMsg->time;
return NowTime-PreTime;
}
else return 0;
break;
default:
return CallNextHookEx(NULL,nCode,wparam,lparam);
}
return 0;}
请问下哪有错啊,很急
解决方案
cpp中定义错了修改下试试,把static删了也
LRESULT CALLBACK CMFCApplication2Dlg::JournalRecordProc(int nCode,WPARAM wparam,LPARAM lparam)
LRESULT CALLBACK CMFCApplication2Dlg::JournalPlaybackProc(int nCode,WPARAM wparam,LPARAM lparam)
解决方案二:
调用在定义前,这种情况需要先声明函数
解决方案三:
在代码前面加上: static LRESULT CALLBACK JournalRecordProc(int nCode,WPARAM wparam,LPARAM lparam);
static LRESULT CALLBACK JournalPlaybackProc(int nCode,WPARAM wparam,LPARAM lparam);