DWORD rc = ::DestroyWindow( (HWND)MessageWindow() );
MessageWindow mw; mw.Destroy();
nsNativeAppSupportWin::OnLastWindowClosing( nsIXULWindow *aWindow ) {    if ( !mServerMode )        return NS_OK;    // If the last window closed is our special "turbo" window made    // in StartServerMode(), don't do anything.    nsCOMPtr<nsIDocShell> docShell;    ( void )aWindow->GetDocShell( getter_AddRefs( docShell ) );    nsCOMPtr<nsIDOMWindow> domWindow( do_GetInterface( docShell ) );    if ( domWindow == mInitialWindow ) {        mInitialWindow = nsnull;        return NS_OK;    }    // If the last window closed is our confirmation dialog,    // don't do anything.    if ( mLastWindowIsConfirmation ) {        mLastWindowIsConfirmation = PR_FALSE;        return NS_OK;    }    nsresult rv;    // If activated by the browser.turbo.singleProfileOnly pref,    // check for multi-profile situation and turn off turbo mode    // if there are multiple profiles.    PRBool singleProfileOnly = PR_FALSE;    nsCOMPtr<nsIPref> prefService( do_GetService( NS_PREF_CONTRACTID, &rv ) );    if ( NS_SUCCEEDED( rv ) ) {        prefService->GetBoolPref( "browser.turbo.singleProfileOnly", &singleProfileOnly );    }    if ( singleProfileOnly ) {        nsCOMPtr<nsIProfile> profileMgr( do_GetService( NS_PROFILE_CONTRACTID, &rv ) );        if ( NS_SUCCEEDED( rv ) ) {            PRInt32 profileCount = 0;            if ( NS_SUCCEEDED( profileMgr->GetProfileCount( &profileCount ) ) &&                 profileCount > 1 ) {                // Turn off turbo mode and quit the application.                SetIsServerMode( PR_FALSE );                nsCOMPtr<nsIAppShellService> appShell =                    do_GetService( "@mozilla.org/appshell/appShellService;1", &rv);                if ( NS_SUCCEEDED( rv ) ) {                    appShell->Quit();                }                return NS_OK;            }        }    }    if ( !mShownTurboDialog ) {        PRBool showDialog = PR_TRUE;        if ( NS_SUCCEEDED( rv ) )            prefService->GetBoolPref( "browser.turbo.showDialog", &showDialog );        nsCOMPtr<nsIDOMWindowInternal> domWindowInt ( do_GetInterface( docShell ) );        if ( showDialog && domWindowInt ) {            nsCOMPtr<nsIDOMWindow> newWindow;            mShownTurboDialog = PR_TRUE;            mLastWindowIsConfirmation = PR_TRUE;            domWindowInt->OpenDialog( NS_LITERAL_STRING( "chrome://navigator/content/turboDialog.xul" ),                                      NS_LITERAL_STRING( "_blank" ),                                      NS_LITERAL_STRING( "chrome,modal,titlebar,centerscreen,dialog" ),                                      nsnull, getter_AddRefs( newWindow ) );        }    }    nsCOMPtr<nsIAppShellService> appShell =        do_GetService( "@mozilla.org/appshell/appShellService;1", &rv);    if ( NS_SUCCEEDED( rv ) ) {        // Instead of staying alive, launch a new instance of the application and then        // terminate for real.  We take steps to ensure that the new instance will run        // as a "server process" and not try to pawn off its request back on this        // instance.        // Grab mutex.  Process termination will release it.        Mutex mutexLock = Mutex(mMutexName);        NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE );        // Turn off MessageWindow so the other process can't see us.        DWORD rc = ::DestroyWindow( (HWND)MessageWindow() );            // Launch another instance.        char buffer[ _MAX_PATH ];        // Same application as this one.        ::GetModuleFileName( 0, buffer, sizeof buffer );        // Clean up name so we don't have to worry about enclosing it in quotes.        ::GetShortPathName( buffer, buffer, sizeof buffer );        nsCAutoString cmdLine( buffer );        // The new process must run in turbo mode (no splash screen, no window, etc.).        cmdLine.Append( " -turbo" );            // Now do the Win32 stuff...        STARTUPINFO startupInfo;        ::GetStartupInfo( &startupInfo );        PROCESS_INFORMATION processInfo;        rc = ::CreateProcess( 0,                              (LPTSTR)cmdLine.get(),                              0,                              0,                              0,                              0,                              0,                              0,                              &startupInfo,                              &processInfo );            // Turn off turbo mode and quit the application.        SetIsServerMode( PR_FALSE );        appShell->Quit();        // Done.  This app will now commence shutdown.    }    return NS_OK;}