Пример #1
0
 __except (excode = _exception_code(), EXCEPTION_CONTINUE_SEARCH ) { }
__declspec(dllexport) int WINAPI Win32Main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    HRESULT hr;

    // seed the random number generator with the current time
    // (GetTickCount may be semi-predictable on server startup, so we add the 
    // clock time to shake things up a bit)
    srand(GetTickCount() + (int)time(NULL));

	// mmf why is this done?
    // shift the stack locals and the heap by a random amount.            
    char* pzSpacer = new char[4 * (int)random(21, 256)];
    pzSpacer[0] = *(char*)_alloca(4 * (int)random(1, 256));


    __try { 
        do {
            #ifdef SRVLOG
                InitializeDebugf();
            #endif

			InitializeLogchat();  // mmf

            BreakOnError(hr = Window::StaticInitialize());

// BUILD_DX9 - KGJV use runtime dynamic instead at preprocessor level
			if (g_papp->IsBuildDX9())
			{
				BreakOnError(hr = g_papp->Initialize(lpszCmdLine));
			}
			else
			{
				// Don't throw an error, if the user selects cancel it can return E_FAIL.
				hr = g_papp->Initialize(lpszCmdLine);
			}
// BUILD_DX9

            //
            // Win32App::Initialize() return S_FALSE if this is a command line app and
            // we shouldn't run the message loop
            //

            if (SUCCEEDED(hr) && S_FALSE != hr) {
                Window::MessageLoop();
            }

            g_papp->Terminate();
            Window::StaticTerminate();

            #ifdef SRVLOG
                TerminateDebugf();
            #endif

			TerminateLogchat(); // mmf

        } while (false);
    }  __except (g_papp->OnException(_exception_code(), (ExceptionData*)_exception_info())){
    }  
    delete pzSpacer;

    return 0;
}