Annotation of mstools/mfc/src/winmain.cpp, revision 1.1.1.3

1.1       root        1: // This is a part of the Microsoft Foundation Classes C++ library.
                      2: // Copyright (C) 1992 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 Microsoft
                      7: // QuickHelp documentation provided with the library.
                      8: // See these sources for detailed information regarding the
                      9: // Microsoft Foundation Classes product.
                     10: 
                     11: #include "afxwin.h"
                     12: #pragma hdrstop
                     13: 
                     14: #ifdef AFX_CORE_SEG
                     15: #pragma code_seg(AFX_CORE_SEG)
                     16: #endif
                     17: 
                     18: /////////////////////////////////////////////////////////////////////////////
                     19: // Standard WinMain implementation
                     20: //  Can be replaced as long as 'AfxWinInit' is called first
                     21: 
                     22: #ifndef _WINDLL
                     23: extern "C"
                     24: int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     25:        LPSTR lpCmdLine, int nCmdShow)
                     26: {
                     27:        int nReturnCode = -1;
                     28: 
                     29:        // AFX internal initialization
                     30:        if (!AfxWinInit(hInstance, hPrevInstance, lpCmdLine, nCmdShow))
                     31:                goto InitFailure;
                     32: 
                     33:        // App global initializations (rare)
                     34:        if (hPrevInstance == NULL && !AfxGetApp()->InitApplication())
                     35:                goto InitFailure;
                     36: 
                     37:        // Perform specific initializations
                     38:        if (!AfxGetApp()->InitInstance())
                     39:                goto InitFailure;
                     40: 
                     41:        nReturnCode = AfxGetApp()->Run();
                     42: 
                     43: InitFailure:
                     44:        AfxWinTerm();
                     45:        return nReturnCode;
                     46: }
                     47: #else
                     48: // _WINDLL initialization
                     49: 
1.1.1.2   root       50: #ifndef _NTWIN
1.1       root       51: extern "C"
                     52: int FAR PASCAL LibMain(HINSTANCE hInstance,
                     53:        WORD wDataSegment, WORD wHeapSize, LPSTR lpszCmdLine)
                     54: {
                     55:        // Initialize DLL's instance(/module) not the app's
                     56:        if (!AfxWinInit(hInstance, NULL, lpszCmdLine, 0))
                     57:        {
                     58:                AfxWinTerm();
                     59:                return 0;       // Init Failed
                     60:        }
                     61: 
                     62:        // initialize the single instance DLL
                     63:        if (!AfxGetApp()->InitInstance())
                     64:        {
                     65:                AfxWinTerm();
                     66:                return 0;
                     67:        }
                     68: 
                     69:        // nothing to run
                     70:        return 1;   // ok
                     71: }
1.1.1.2   root       72: #else //_NTWIN
1.1.1.3 ! root       73: #include <process.h>   // for _cexit()
        !            74: 
        !            75: // NOTE: To provide your own DLL entry point use a different name than
        !            76: //     AfxLibMain, but make sure to call AfxLibMain much like _CRT_INIT
        !            77: //     is called from AfxLibMain itself.
1.1.1.2   root       78: 
                     79: extern "C" BOOL WINAPI
                     80: _CRT_INIT(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved);
                     81: 
                     82: extern "C" int APIENTRY
1.1.1.3 ! root       83: AfxLibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
1.1.1.2   root       84: {
1.1.1.3 ! root       85:        if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
1.1.1.2   root       86:        {
1.1.1.3 ! root       87:                // Initialize the C/C++ runtime first
        !            88:                if (!_CRT_INIT(hInstance, dwReason, lpReserved))
        !            89:                        return 0;               // CRT init Failed
1.1.1.2   root       90:        }
                     91: 
1.1.1.3 ! root       92:        if (dwReason == DLL_PROCESS_ATTACH)
        !            93:        {
        !            94:                // Initialize DLL's instance(/module) not the app's
        !            95:                if (!AfxWinInit(hInstance, NULL, "", 0))
        !            96:                {
        !            97:                        AfxWinTerm();
        !            98:                        return 0;               // Init Failed
        !            99:                }
        !           100: 
        !           101:                // initialize the single instance DLL
        !           102:                if (!AfxGetApp()->InitInstance())
        !           103:                {
        !           104:                        AfxWinTerm();
        !           105:                        return 0;
        !           106:                }
        !           107:        }
        !           108:        else if (dwReason == DLL_PROCESS_DETACH)
1.1.1.2   root      109:        {
1.1.1.3 ! root      110:                // Terminate the library before destructors are called
1.1.1.2   root      111:                AfxWinTerm();
1.1.1.3 ! root      112: 
        !           113:                // This should call C++ static destructors
        !           114:                _cexit();
1.1.1.2   root      115:        }
                    116: 
1.1.1.3 ! root      117:        if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
1.1.1.2   root      118:        {
1.1.1.3 ! root      119:                // Terminate the C/C++ runtime last
        !           120:                if (!_CRT_INIT(hInstance, dwReason, lpReserved))
        !           121:                        return 0;               // CRT term     Failed
1.1.1.2   root      122:        }
                    123: 
                    124:        return 1;   // ok
                    125: }
                    126: #endif //_NTWIN
1.1       root      127: #endif //_WINDLL
                    128: 
                    129: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.