編譯都過了,就是運行的時候出現exception in mail.exe: 0xC0000005: Access Violation.彈框。求大神幫助。
#include "stdafx.h"
#ifdef AFX_CORE1_SEG
#pragma code_seg(AFX_CORE1_SEG)
#endif
/////////////////////////////////////////////////////////////////////////////
// Standard WinMain implementation
// Can be replaced as long as 'AfxWinInit' is called first
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL);
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();
// AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure;
// App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;
// Perform specific initializations
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();
InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif
AfxWinTerm();
return nReturnCode;
}
出錯時黃色指標指向if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)!!!
在網上看了很多資料,但還是解決不了。
uj5u.com熱心網友回復:
你的pThread 可能為空,你前面獲取執行緒有問題,或者不能在這個位置獲取到uj5u.com熱心網友回復:
那這個要怎么改呢我在前面加了 pThread = (pThread*) malloc (pThread); 但又提示(pThread*)的右括號有錯
求指導
uj5u.com熱心網友回復:
首先自己查錯的話,呼叫堆疊試試,然后找到源頭去網上查原因。一般這種錯誤是指標為空的原因,希望能幫到你。uj5u.com熱心網友回復:
#include "stdafx.h"
#ifdef AFX_CORE1_SEG
#pragma code_seg(AFX_CORE1_SEG)
#endif
/////////////////////////////////////////////////////////////////////////////
// Standard WinMain implementation
// Can be replaced as long as 'AfxWinInit' is called first
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
ASSERT(hPrevInstance == NULL);
int nReturnCode = -1;
CWinThread* pThread = AfxGetThread();
CWinApp* pApp = AfxGetApp();
// AFX internal initialization
if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
goto InitFailure;
// App global initializations (rare)
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;
// Perform specific initializations
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
nReturnCode = pThread->Run();
InitFailure:
#ifdef _DEBUG
// Check for missing AfxLockTempMap calls
if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
{
TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
AfxGetModuleThreadState()->m_nTempMapLock);
}
AfxLockTempMaps();
AfxUnlockTempMaps(-1);
#endif
AfxWinTerm();
return nReturnCode;
}
不知道動了什么 現在錯誤又指向
if (pApp != NULL && !pApp->InitApplication())
goto InitFailure;
了
uj5u.com熱心網友回復:
重新創建一個類似的工程,自己比對一下~uj5u.com熱心網友回復:
應該是#include "stdafx.h"
#include "afxwin.h"
void main()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改錯誤代碼以符合您的需要
_tprintf(_T("錯誤: MFC 初始化失敗\n"));
}
吧?
uj5u.com熱心網友回復:
我加了這幾行后,現在變成 CWinApp* pApp = AfxGetApp(); 又錯了,還是那個問題
uj5u.com熱心網友回復:
// Standard WinMain implementation// Can be replaced as long as 'AfxWinInit' is called first
不要 AfxWinMain
uj5u.com熱心網友回復:
還是不太明白,有點暈,能不能把你改過的代碼發出來給我看看。 感謝大神

uj5u.com熱心網友回復:
崩潰的時候在彈出的對話框按相應按鈕進入除錯,按Alt+7鍵查看Call Stack即“呼叫堆疊”里面從上到下列出的對應從里層到外層的函式呼叫歷史。雙擊某一行可將游標定位到此次呼叫的源代碼或匯編指令處,看不懂時雙擊下一行,直到能看懂為止。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/139734.html
標籤:基礎類
上一篇:installshield shortcuts添加卸載檔案 打包安裝后有沒卸載檔案
下一篇:關于CString輸出的問題?
