下面是一小段程序,但是编译出错了
void CMyFormView::Run()
{
}DWORD WINAPI CMyFormView::RunThread(LPVOID lpParameter)
{
Run();
return 0;
}void CMyFormView::OnButtonT() 
{
CreateThread( NULL, 0, RunThread, NULL, 0, NULL );}
这是一个大概的框架,但是编译错误如下:
error C2664: 'CreateThread' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)'
        None of the functions with this name in scope match the target type刚刚学习,还不太明白,请教一下原因,如何修改?

解决方案 »

  1.   

    线程函数需要使用静态(static)成员函数或全局函数
      

  2.   

    将 RunThread 定义成全局或静态函数
      

  3.   

    参数的问题。
    成员函数隐藏了参数this,比需要的多
      

  4.   

    线程函数需要使用静态(static)成员函数或全局函数
      

  5.   

    已改为static DWORD   WINAPI   CMyFormView::RunThread(LPVOID   lpParameter) 但是我编译的时候报错,
    error C2352: 'CMyFormView::Run' : illegal call of non-static member function难道都要定义为static类型吗?
      

  6.   

    like this:
    class A
    {
     public:
        ....
     static DWORD CALLBACK ThreadProc(void *lpVoid);
     ...
    };
      

  7.   

    头文件中:static   DWORD       WINAPI       CMyFormView::RunThread(LPVOID       lpParameter)   m_ColListCtrl 是类控件变量;CPP中:void   CMyFormView::Run() 

          CString str = m_ColListCtrl.GetItemText(2, 4);
    } DWORD   WINAPI   CMyFormView::RunThread(LPVOID   lpParameter) 

    Run(); 
    return   0; 
    } void   CMyFormView::OnButtonT()   

    CreateThread(   NULL,   0,   RunThread,   NULL,   0,   NULL   ); } 编译的时候报错, 
    error   C2352:   'CMyFormView::Run'   :   illegal   call   of   non-static   member   function 
    需要把Run()定义为static才行,而且需要把run()中调用的变量和函数都定义为static类型,有点麻烦,
    哪位高人有别的方式可以调用run();不需要把run()定义为static类型;
    给指点一下,多谢!
    如果我描述的不清楚,请指出。
      

  8.   

    void       CMyFormView::Run()   
    {   
                CString   str   =   m_ColListCtrl.GetItemText(2,   4); 
    }   DWORD       WINAPI       CMyFormView::RunThread(LPVOID       lpParameter)   
    {   CMyFormView* pview = (CMyFormView*)lpParameter;
    pview->Run();   
    return       0;   
    }   void       CMyFormView::OnButtonT()       
    {   
    CreateThread(       NULL,       0,       RunThread,       this,       0,       NULL       );   }   
      

  9.   

    定义成 
    static DWORD       WINAPI       CMyFormView::RunThread(LPVOID       lpParameter)   
      

  10.   

    CMyFormView* pview = (CMyFormView*)lpParameter;这句不太懂,不过确实没问题了。