MFC,图像处理,工作线程调用类的成员函数总出错
工作线程调用类的成员函数,总是出现大红叉的那个提示,为什么?代码如下:
//控制函数,定义线程
static UINT Thread_FatigueAlarm(LPVOID pParam)
{
CUsepicoptdllView* p_usepicoptdllview = (CUsepicoptdllView*)pParam;
if((p_usepicoptdllview == NULL) || (!p_usepicoptdllview- >IsKindOf(RUNTIME_CLASS(CUsepicoptdllView))))
{
AfxMessageBox("参数传入失败,退出线程");
return 1;
}
p_usepicoptdllview->OnPicBinary();
/*int globalCounter;
globalCounter++;
if(globalCounter > 9999)
globalCounter = 0;
*/
Sleep(1000);
return UINT(0);
}
void CUsepicoptdllView::OnFatigueAlarmRun()
{
CUsepicoptdllView *pObject = new CUsepicoptdllView(); //创建对象
m_pThread = new CWinThread(); //创建线程
m_pThread->m_bAutoDelete = false;
m_pThread = AfxBeginThread(Thread_FatigueAlarm,pObject); //创建工作者线程
if(m_pThread != NULL)
MessageBox("线程调用成功");
}
主要是一调用p_usepicoptdllview->OnPicBinary();这个函数就出错,程序没有走到OnPicBinary()函数里面。 线程 mfc
[解决办法]
unsigned WINAPI _ThreadEntry(LPVOID pParam)
{
CThreadEx * pThread = (CThreadEx *)pParam;
ASSERT_DLL(pThread != NULL);
ASSERT_DLL(pThread->m_hThread != NULL);
unsigned nResult = 0;
if (pThread->InitInstance())
{
nResult = pThread->Run();
}
nResult = pThread->ExitInstance();
pThread->m_hThread = NULL;
_endthreadex(nResult);
return nResult;
}
int CThreadEx::Run()
{
return 0;
}
BOOL CThreadEx::CreateThread(unsigned dwCreateFlags, UINT nStackSize,
LPSECURITY_ATTRIBUTES lpSecurityAttrs)
{
ASSERT_DLL(m_hThread == NULL);
LPVOID _MyThread = (LPVOID)this;
m_hThread = (HANDLE)_beginthreadex(lpSecurityAttrs,
nStackSize,
_ThreadEntry,
_MyThread,
dwCreateFlags,
&m_nThreadID);
m_iSuspendCount = (dwCreateFlags
[解决办法]
CREATE_SUSPENDED)?1:0;
return (m_hThread)?TRUE:FALSE;
}