我正在尝试使用MFC创建一个工作线程,所以这里是代码:
struct ThreadParam
{
HWND mDlg; // Note: A handle.
};
UINT TestMFCThread::Test( LPVOID pParam ){
//do work!
}
void TestMFCThread::OnBnClickedButton2()
{
ThreadParam* param = new ThreadParam;
param->mDlg = m_hWnd;
AfxBeginThread(Test, param);
}
但它给了我这个错误:
1 IntelliSense: no instance of overloaded function "AfxBeginThread" matches the argument list
argument types are: (UINT (LPVOID pParam), ThreadParam *)
idk什么错了它应该是对的!
答案 0 :(得分:1)
从AfxBeginThread()的文档中,您需要将第二个参数强制转换为LPVOID
:
AfxBeginThread(Test, (LPVOID) param);
并将Test
的调用约定设置为__cdecl
:
UINT __cdecl Test( LPVOID lParam)