home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / winmain.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  2KB  |  68 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CORE1_SEG
  14. #pragma code_seg(AFX_CORE1_SEG)
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Standard WinMain implementation
  19. //  Can be replaced as long as 'AfxWinInit' is called first
  20.  
  21. int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  22.     LPTSTR lpCmdLine, int nCmdShow)
  23. {
  24.     ASSERT(hPrevInstance == NULL);
  25.  
  26.     int nReturnCode = -1;
  27.     CWinThread* pThread = AfxGetThread();
  28.     CWinApp* pApp = AfxGetApp();
  29.  
  30.     // AFX internal initialization
  31.     if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
  32.         goto InitFailure;
  33.  
  34.     // App global initializations (rare)
  35.     if (pApp != NULL && !pApp->InitApplication())
  36.         goto InitFailure;
  37.  
  38.     // Perform specific initializations
  39.     if (!pThread->InitInstance())
  40.     {
  41.         if (pThread->m_pMainWnd != NULL)
  42.         {
  43.             TRACE0("Warning: Destroying non-NULL m_pMainWnd\n");
  44.             pThread->m_pMainWnd->DestroyWindow();
  45.         }
  46.         nReturnCode = pThread->ExitInstance();
  47.         goto InitFailure;
  48.     }
  49.     nReturnCode = pThread->Run();
  50.  
  51. InitFailure:
  52. #ifdef _DEBUG
  53.     // Check for missing AfxLockTempMap calls
  54.     if (AfxGetModuleThreadState()->m_nTempMapLock != 0)
  55.     {
  56.         TRACE1("Warning: Temp map lock count non-zero (%ld).\n",
  57.             AfxGetModuleThreadState()->m_nTempMapLock);
  58.     }
  59.     AfxLockTempMaps();
  60.     AfxUnlockTempMaps(-1);
  61. #endif
  62.  
  63.     AfxWinTerm();
  64.     return nReturnCode;
  65. }
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68.