AfxBeginThread(PostData,NULL); 函数参数不对,类型和数量有问题

解决方案 »

  1.   

    类的成员函数有一个默认的参数(this),而线程函数需要UINT proc(LPARAM),若使用成员函数,实际上是具有两个参数的函数原型,当然不行了.如果你一定要使用成员函数的话,可以使用静态成员函数.
      

  2.   

    那就学我吧,也别这么固执DWORD WINAPI ServerThread(LPVOID lpParameter)
    {
    CoInitialize(NULL);
    CMyDlg* p = (CMyDlg*)lpParameter;
    do
    {
    BOOL b = p->OnDownload();
    if( !b )
    Sleep( 1000*10 );
    }while(1);
    CoUninitialize();
    ExitThread(0);
    return(0);
    }
      

  3.   

    因为有隐含的this指针.
    定义为静态成员函数也可以.
      

  4.   

    void CSp_14Dlg::OnOK() 
    { AfxBeginThread(PostData,NULL); } 
    static UINT PostData(LPVOID pParam); static UINT CSp_14Dlg::PostData(LPVOID pParam) 

    Get(); 
    } 结果还是不行!!!
      

  5.   

    void CSp_14Dlg::OnOK() 
    { AfxBeginThread(CSp_14Dlg::PostData,NULL); } static UINT CSp_14Dlg::PostData(LPVOID pParam) 

    Get(); 

      

  6.   

    static UINT PostData(LPVOID pParam); 应该放在类中声明。
    还有
    PostData要返回值呀!其他都没问题了
      

  7.   

    UINT PostData(LPVOID pParam)
    {
         CSp_14Dlg * p = (CSp_14Dlg*)pParam;
         p->PostData(pParam);
         return 0;
    }
    void CSp_14Dlg::OnOK() 
    { AfxBeginThread(PostData,this); } UINT CSp_14Dlg::PostData(LPVOID pParam) 

    Get(); 

      

  8.   

    如果定义为静态函数
    出错信息为
    C:\Windows\Desktop\sam_sp_teach_141\sp_14\sp_14Dlg.cpp(47) : error C2724: 'PostData' : 'static' should not be used on member functions defined at file scope
      

  9.   

    而且在线程函数里无法调用类的其他成员函数出错信息为C:\Windows\Desktop\sam_sp_teach_141\sp_14\sp_14Dlg.cpp(48) : error C2352: 'CSp_14Dlg::Get' : illegal call of non-static member function        c:\windows\desktop\sam_sp_teach_141\sp_14\sp_14dlg.h(19) : see declaration of 'Get'

      

  10.   

    在windows中,
    类的非static成员函数必须是__fastcall,这是不能更改,因此只有使用static function.
    不过,使用thunk可以让成员函数变得可以作为callback函数,但是这也让程序变得高度不可移植。所以还是使用static function吧。
      

  11.   

    试试:
    ThreadProc(LPVOID pParam)
    {
      CYourClass *pCls = (CYourClass *)pParam;
      pCls->xxxx();
    }xxx()
    {
      CYourClass m_cls;
      AfxBeginThread(ThreadProc,&m_cls);
    }