关于线程的错误信息,怎么改?高手!!!
日期:2007-10-13 荐:
关于线程的错误信息,怎么改?高手!!!刚刚学习编写线程的小例子:void CMultiprocessDlg::OnStart() {hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,NULL,0,&ThreadID);}void CMultiprocessDlg::OnStop() {TerminateThread(hThread,1);}void CMultiprocessDlg::ThreadProc(){CTime time;CString m_time;for(;;){time = CTime::GetCurrentTime();m_time = time.Format("%H:%M%S");::SetDlgItemText(AfxGetMainWnd()->m_hWnd, IDC_TIME, m_time);Sleep(1000);}}错误提示为:error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'DWORD CMultiprocessDlg::ThreadProc(){CTime time;CString m_time;for(;;){time = CTime::GetCurrentTime();m_time = time.Format("%H:%M%S");::SetDlgItemText(AfxGetMainWnd()->m_hWnd, IDC_TIME, m_time);Sleep(1000);} return 0;}unsigned __stdcall CMultiprocessDlg::ThreadProc(){CTime time;CString m_time;for(;;){time = CTime::GetCurrentTime();m_time = time.Format("%H:%M%S");::SetDlgItemText(AfxGetMainWnd()->m_hWnd, IDC_TIME, m_time);Sleep(1000);}}ThreadProc在类中应该定义为static的。//hclass CMultiprocessDlg{...static DWORD ThreadProc(LPVOID param);...};//cppDWORD CMultiprocessDlg::ThreadProc(LPVOID param){...return 0;}不行啊还是?静态成员函数.我都试过了,还是不行,为什么?后来我改了,不用createthread(),而用了CWinThread *pThread = AfxBeginThread(ThreadP,this);这样问题就解决了。看来AfxBeginThread比前者好用。静态成员函数或者全局函数
标签: