.h中
class CToolDlg : public CDialog
{
// Construction
public:
 DWORD WINAPI BuildFileProc(LPVOID lpParam);
 DWORD BuildFile();
........
}
 
.cpp中
void CToolDlg::OnOK() 
{
 // TODO: Add extra validation here
 HANDLE hThread = NULL;
 DWORD dwId = 0;
 hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)BuildFileProc,this,0,&dwId);
 return ;
}
 
DWORD WINAPI CToolDlg::BuildFileProc(LPVOID lpParam)
{
 CToolDlg* pThis = (CToolDlg *)lpParam;
 return pThis->BuildFile();
}
 
DWORD CToolDlg::BuildFile()
{
}
 
 
编译报错:error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'
        None of the functions with this name in scope match the target type
 
 
如何解决?谢谢

解决方案 »

  1.   

    hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)BuildFileProc,this,0,&dwId);
    你不要加(LPTHREAD_START_ROUTINE),写成这样
    hThread = CreateThread(NULL,0,BuildFileProc,0,0,&dwId);
      

  2.   

    线程的入口函数BuildFileProc()应该是全局的,而不应是某个类的成员函数
      

  3.   

    可以是类函数,我以前看别人这样调用过:
    DWORD WINAPI CToolDlg::BuildFileProc(LPVOID lpParam)
    {
     CToolDlg* pThis = (CToolDlg *)lpParam;
     return pThis->BuildFile();
    }