现派生
class CcomThread : public CWinThread
CcomThread * p_myThread;//定义指针对象p_myThread=(CcomThread*)AfxBeginThread(RUNTIME_CLASS(CcomThread),THREAD_PRIORITY_NORMAL,0,0); //开线程
现在想关掉
int nCount = 0;
DWORD dwStatus;
if(p_myThread!=NULL)
{
VERIFY(::GetExitCodeThread(p_myThread->m_hThread,&dwStatus));
if(dwStatus==STILL_ACTIVE)
{
nCount++;
m_bDone = TRUE;
}如果仍为运行状态,则终止
else{
delete p_myThread;
p_myThread=NULL;
}}//如果已经终止,则删除该线程对象 }
if (nCount == 0) { // 线程已终止,则关闭程序
CDialog::OnClose();// 在SDI和MDI程序中应改为void CMainFrame::OnClose()函数
}
else // 否则,发送WM_CLOSE消息
PostMessage(WM_CLOSE, 0, 0); 请编译error C2248: 'CcomThread::~CcomThread' : cannot access protected member declared in class 'CcomThread'
这个怎么处理?
class CcomThread : public CWinThread
CcomThread * p_myThread;//定义指针对象p_myThread=(CcomThread*)AfxBeginThread(RUNTIME_CLASS(CcomThread),THREAD_PRIORITY_NORMAL,0,0); //开线程
现在想关掉
int nCount = 0;
DWORD dwStatus;
if(p_myThread!=NULL)
{
VERIFY(::GetExitCodeThread(p_myThread->m_hThread,&dwStatus));
if(dwStatus==STILL_ACTIVE)
{
nCount++;
m_bDone = TRUE;
}如果仍为运行状态,则终止
else{
delete p_myThread;
p_myThread=NULL;
}}//如果已经终止,则删除该线程对象 }
if (nCount == 0) { // 线程已终止,则关闭程序
CDialog::OnClose();// 在SDI和MDI程序中应改为void CMainFrame::OnClose()函数
}
else // 否则,发送WM_CLOSE消息
PostMessage(WM_CLOSE, 0, 0); 请编译error C2248: 'CcomThread::~CcomThread' : cannot access protected member declared in class 'CcomThread'
这个怎么处理?
{
pThread->m_bAutoDelete = FALSE;
pThread->ResumeThread();
...
delete pThread;
}
运行库采用多线程
:\program files\microsoft visual studio\vc98\mfc\include\afxver_.h(130) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
Error executing cl.exe.
运行库采用多线程dll
SMSTestDlg.obj : error LNK2005: "int m_bDone" (?m_bDone@@3HA) already defined in SMSTest.obj
LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/SMSTest.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
m_bDone 只是一个全局布尔变量,根本没有定义int m_bDone,请指点!
BOOL TerminateThread(
HANDLE hThread,
DWORD dwExitCode
);然后WaitForSingleObject一下,再delete,不能直接delete。2。全局m_bDone所在的头文件被重复包含了。
在别的地方要用的时候先extern int m_bDone定义一下。