void AFXAPI AfxAbort() { TRACE0("AfxAbort called.\n"); AfxWinTerm(); abort(); }
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { ASSERT(hPrevInstance == NULL); int nReturnCode = -1; __try { 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) { TRACE(traceAppMsg, 0, "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) { TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(-1); #else ; #endif } __except(RecordExceptionInfo(GetExceptionInformation())) { } // must call AfxWinTerm after handling exception or we'll crash // again trying to destroy the tooltip window AfxWinTerm(); return nReturnCode; }
extern "C" int WINAPI #endif WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { ASSERT(hPrevInstance == NULL); lpCmdLine; int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // AFX internal initialization LPTSTR p = GetCommandLine(); while (*p && (*p != _T(' '))) p++; if (*p) p++; if (!AfxWinInit(hInstance, hPrevInstance, p, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); nReturnCode = pApp->Run(); ASSERT_VALID(pApp); InitFailure: AfxWinTerm(); return nReturnCode; }
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 bool InitSuccess = AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow); // App global initializations (rare) if (pApp != NULL) InitSuccess = InitSuccess && pApp->InitApplication(); // Perform specific initializations InitSuccess = InitSuccess && pThread->InitInstance(); // Run the BCI2000 core module. if( InitSuccess ) { CoreModuleMFC coreModule; nReturnCode = ( coreModule.Run( __argc, __argv ) ? 0 : -1 ); } else { if (pThread->m_pMainWnd != NULL) { TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); pThread->m_pMainWnd->DestroyWindow(); } } pThread->ExitInstance(); #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; }
BOOL DoExit() { #ifdef _DEBUG // Check for missing AfxLockTempMap calls if (AfxGetModuleThreadState()->m_nTempMapLock != 0) { TRACE(traceAppMsg, 0, "Warning: Temp map lock count non-zero (%ld).\n", AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(-1); #endif AfxWinTerm(); return TRUE; }
int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { char szLogFileName[_MAX_DIR]; if (GetRecommandLogFileName(szLogFileName) == false) return FALSE; InitLog(MLOGSTYLE_DEBUGSTRING|MLOGSTYLE_FILE, szLogFileName); // Wrap WinMain in a structured exception handler (different from C++ // exception handling) in order to make sure that all access violations // and other exceptions are displayed - regardless of when they happen. // This should be done for each thread, if at all possible, so that exceptions // will be reliably caught, even inside the debugger. #ifdef SUPPORT_EXCEPTIONHANDLING char szDumpFileName[_MAX_DIR]; strcpy(szDumpFileName, szLogFileName); strcat(szDumpFileName, ".dmp"); __try { #endif // The code inside the __try block is the MFC version of AfxWinMain(), // copied verbatim from the MFC source code. ASSERT(hPrevInstance == NULL); int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // AFX internal initialization if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE(_T("Warning: Destroying non-NULL m_pMainWnd\n")); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); nReturnCode = pApp->Run(); ASSERT_VALID(pApp); InitFailure: #ifdef _DEBUG // Check for missing AfxLockTempMap calls if (AfxGetModuleThreadState()->m_nTempMapLock != 0) { TRACE(_T("Warning: Temp map lock count non-zero (%ld).\n"), AfxGetModuleThreadState()->m_nTempMapLock); } AfxLockTempMaps(); AfxUnlockTempMaps(-1); #endif AfxWinTerm(); return nReturnCode; #ifdef SUPPORT_EXCEPTIONHANDLING } // __except(MFilterException(GetExceptionInformation())){ __except(CrashExceptionDump(GetExceptionInformation(), szDumpFileName)){ // char szFileName[_MAX_DIR]; // GetModuleFileName(NULL, szFileName, _MAX_DIR); // WinExec(szFileName, SW_SHOW); // Launch again //MMatchServer::GetInstance()->CheckMemoryTest(); //MGetServerStatusSingleton()->Dump(); } #endif return 0; }
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID) { CWinApp* pApp = AfxGetApp(); if (dwReason == DLL_PROCESS_ATTACH) { // initialize MFC exception handling #ifndef _AFX_OLD_EXCEPTIONS set_terminate(&AfxStandardTerminate); #endif _set_new_handler(&AfxNewHandler); // initialize DLL's instance(/module) not the app's if (!AfxWinInit(hInstance, NULL, &afxChNil, 0)) { AfxWinTerm(); return FALSE; // Init Failed } // initialize the single instance DLL if (pApp != NULL && !pApp->InitInstance()) { pApp->ExitInstance(); AfxWinTerm(); return FALSE; // Init Failed } } else if (dwReason == DLL_PROCESS_DETACH) { if (pApp != NULL) pApp->ExitInstance(); #ifdef _DEBUG // check for missing AfxLockTempMap calls if (AfxGetThreadState()->m_nTempMapLock != 0) TRACE1("Warning: Temp map lock count non-zero (%ld).\n", AfxGetThreadState()->m_nTempMapLock); #endif // terminate the library before destructors are called AfxWinTerm(); // free safety pool buffer AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); if (pThreadState->m_pSafetyPoolBuffer != NULL) { free(pThreadState->m_pSafetyPoolBuffer); pThreadState->m_pSafetyPoolBuffer = NULL; } #ifdef _DEBUG // trace any memory leaks that may have occurred AfxDumpMemoryLeaks(); #endif // clean up map objects before it is too late delete pThreadState->m_pmapHWND; pThreadState->m_pmapHWND = NULL; delete pThreadState->m_pmapHMENU; pThreadState->m_pmapHMENU = NULL; delete pThreadState->m_pmapHDC; pThreadState->m_pmapHDC = NULL; delete pThreadState->m_pmapHGDIOBJ; pThreadState->m_pmapHGDIOBJ = NULL; delete pThreadState->m_pmapHIMAGELIST; pThreadState->m_pmapHIMAGELIST = NULL; pThreadState->m_mapSocketHandle.CMapPtrToPtr::~CMapPtrToPtr(); pThreadState->m_mapDeadSockets.CMapPtrToPtr::~CMapPtrToPtr(); pThreadState->m_listSocketNotifications.CPtrList::~CPtrList(); } return TRUE; // ok }
int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { #ifdef DISPLAYCONSOLE // Redirection of standard output to console int hCrt; BOOL rep; FILE *hf; _SYSTEM_INFO lps; GetSystemInfo(&lps); rep = AllocConsole(); hCrt = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT); hf = _fdopen( hCrt, "w" ); *stdout = *hf; // stop the buffer on stdout // int i = setvbuf( stdout, NULL, _IONBF, 0 ); // filebuf ff(hCrt); // cout = &ff; cout<<"This Debug Window is defined in WinMain.cpp and will disappear in release mode"<<endl; #endif // DISPLAYCONSOLE // By Matra // create log file for all OCC messages // Message::DefaultMessenger()->AddPrinter (new Message_PrinterOStream ("OCCSampleRun.log", Standard_False)); ASSERT(hPrevInstance == NULL); int nReturnCode = -1; CWinApp* pApp = AfxGetApp(); // new in 2.0 CAS.CADE uses the standard C++ exception mechanism /*#ifdef _DEBUG // By Matra // _Function declaratiob here because you can jump to InitFailure Standard_ErrorHandler _Function; #endif // _DEBUG // By Matra */ // AFX internal initialization if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow)) goto InitFailure; // App global initializations (rare) ASSERT_VALID(pApp); if (!pApp->InitApplication()) goto InitFailure; ASSERT_VALID(pApp); // Perform specific initializations if (!pApp->InitInstance()) { if (pApp->m_pMainWnd != NULL) { TRACE0("Warning: Destroying non-NULL m_pMainWnd\n"); pApp->m_pMainWnd->DestroyWindow(); } nReturnCode = pApp->ExitInstance(); goto InitFailure; } ASSERT_VALID(pApp); #ifdef _DEBUG // By Matra Application: // new in 2.0 CAS.CADE uses the standard C++ exception mechanism // if(DoesNotAbort(_Function)) try { nReturnCode = pApp->Run(); } // if(_Function.Catches(STANDARD_TYPE(Standard_Failure))) catch(Standard_Failure) { Standard_SStream ostr; ostr<<Standard_Failure::Caught()<<"\n\0"; CString aMsg = ostr.str().c_str(); MessageBoxW (NULL, aMsg, L"CasCade Error", MB_ICONERROR); goto Application; // restart application loop } #else // _DEBUG // By Matra nReturnCode = pApp->Run(); #endif // _DEBUG // By Matra ASSERT_VALID(pApp); 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(); #endif AfxWinTerm(); #ifdef DISPLAYCONSOLE // By Matra // ferme la console pour le cout fclose( stdout ); //hCrt = _fcloseall(); :-) rep = FreeConsole(); #endif // DISPLAYCONSOLE // By Matra return nReturnCode; }