MFC对话框线程传入指针操作UpdateData 崩溃
structGetHttp{CStringwww;intsave;CStringaddress;CListCtrl*list;CStringwwwaddress;CHTT...
struct GetHttp
{
CString www;
int save;
CString address;
CListCtrl* list;
CString wwwaddress;
CHTTPDlg* p;
};
GetHttp* www = new GetHttp();
www->p = this;
www->list = &this->list1;
CreateThread(NULL,0,httpFdian,(LPVOID)www,0,&aa);
//我是传入结构体指针到线程的
GetHttp* a = (GetHttp*)lpParam;
a->p->edit1++; //正常
a->list->InsertItem(ii,Mun); // 正常
//a->p->UpdateData(false); //该语句崩溃
!求解呀... 展开
{
CString www;
int save;
CString address;
CListCtrl* list;
CString wwwaddress;
CHTTPDlg* p;
};
GetHttp* www = new GetHttp();
www->p = this;
www->list = &this->list1;
CreateThread(NULL,0,httpFdian,(LPVOID)www,0,&aa);
//我是传入结构体指针到线程的
GetHttp* a = (GetHttp*)lpParam;
a->p->edit1++; //正常
a->list->InsertItem(ii,Mun); // 正常
//a->p->UpdateData(false); //该语句崩溃
!求解呀... 展开
5个回答
展开全部
UpdateData确实不能放到子线程,之前我遇到这个问题时查看了源代码,UpdateData引发的操作必须是窗口的产生线程才行。
BOOL CWnd::UpdateData(BOOL bSaveAndValidate)
{
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
CDataExchange dx(this, bSaveAndValidate);
// prevent control notifications from being dispatched during UpdateData
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
HWND hWndOldLockout = pThreadState->m_hLockoutNotifyWindow;
ASSERT(hWndOldLockout != m_hWnd); // must not recurse
pThreadState->m_hLockoutNotifyWindow = m_hWnd;
BOOL bOK = FALSE; // assume failure
TRY
{
DoDataExchange(&dx);
bOK = TRUE; // it worked
}
CATCH(CUserException, e)
{
// validation failed - user already alerted, fall through
ASSERT(!bOK);
// Note: DELETE_EXCEPTION_(e) not required
}
AND_CATCH_ALL(e)
{
// validation failed due to OOM or other resource failure
e->ReportError(MB_ICONEXCLAMATION, AFX_IDP_INTERNAL_FAILURE);
ASSERT(!bOK);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
pThreadState->m_hLockoutNotifyWindow = hWndOldLockout;
return bOK;
}
追问
那么我可以定义线程到 类的public 中吗?
追答
这个随便你,线程函数,线程创建。这个和你UpdateData有关系?
展开全部
把报错的图截出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
轻轻拍哦过。。。 在漂
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议跟踪看一看。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询