我有一個對話框。在這個對話框中:: OnInitDialog()我創建了一個線程AfxBeginThread((AFX_THREADPROC)MyThreadProc,NULL);它崩潰時,我關閉與運行時檢查失敗的對話框,並且它指向thrdcore.cpp文件(Microsoft基礎類C++庫)C++運行時檢查失敗#0 - ESP的值沒有正確保存在...檢查簡單工作線程的點
// first -- check for simple worker thread DWORD nResult = 0; if (pThread->m_pfnThreadProc != NULL) { nResult = (*pThread->m_pfnThreadProc)(pThread->m_pThreadParams); ASSERT_VALID(pThread); }
我有一個代碼,以殺死線程的OnClose功能,但它不」解決問題。有一些可以幫助,我錯過了什麼?我對
HANDLE m_hExit;
DWORD dwResult = 0;
unsigned threadID = 0;
...
OnInitDialog()
{...
m_hExit = (HANDLE)AfxBeginThread((AFX_THREADPROC)MyThreadProc, NULL);
}
OnClose()
{
dwResult = WaitForSingleObject(m_hExit, 0);
if (dwResult == WAIT_TIMEOUT)
{
printf("The thread is still running...\n");
}
else
{
printf("The thread is no longer running...\n");
}
Sleep(10000);
dwResult = WaitForSingleObject(m_hExit, 0);
if (dwResult == WAIT_TIMEOUT)
{
printf("The thread is still running...\n");
}
else
{
printf("The thread is no longer running...\n");
}
CDialog::OnClose();
}
線程函數的代碼是非常大的((((
堆或堆棧已損壞,殺死線程並不能解決問題。您顯示的代碼很好,我懷疑錯誤在線程功能中,請粘貼代碼。 – Matt
您轉換爲AFX_THREADPROC表明您的線程函數可能沒有所需的簽名。它必須具有記錄的線程函數返回類型和參數。 –
我的函數定義UINT WINAPI MyThreadProc(LPVOID pParam) – user2001019