没有重载函数的实例“AfxBeginThread”匹配参数列表

时间:2012-03-20 17:13:22

标签: c++ multithreading mfc

我正在尝试使用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什么错了它应该是对的!

1 个答案:

答案 0 :(得分:1)

AfxBeginThread()的文档中,您需要将第二个参数强制转换为LPVOID

AfxBeginThread(Test, (LPVOID) param);

并将Test的调用约定设置为__cdecl

UINT __cdecl Test( LPVOID lParam)