Back to index

lightning-sunbird  0.9+nobinonly
windbgdlg.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1999
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   John Bandhauer <jband@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
00042 
00043 #include <windows.h>
00044 #include <stdlib.h>
00045 
00046 int WINAPI 
00047 WinMain(HINSTANCE  hInstance, HINSTANCE  hPrevInstance, 
00048         LPSTR  lpszCmdLine, int  nCmdShow)
00049 {
00050     /* support for auto answering based on words in the assertion.
00051      * the assertion message is sent as a series of arguements (words) to the commandline.
00052      * set a "word" to 0xffffffff to let the word not affect this code.
00053      * set a "word" to 0xfffffffe to show the dialog.
00054      * set a "word" to 0x5 to ignore (program should continue).
00055      * set a "word" to 0x4 to retry (should fall into debugger).
00056      * set a "word" to 0x3 to abort (die).
00057      */
00058     DWORD regType;
00059     DWORD regValue = -1;
00060     DWORD regLength = sizeof regValue;
00061     HKEY hkeyCU, hkeyLM;
00062     RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyCU);
00063     RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyLM);
00064     const char * const * argv = __argv;
00065     for (int i = __argc - 1; regValue == (DWORD)-1 && i; --i) {
00066         bool ok = false;
00067         if (hkeyCU)
00068             ok = RegQueryValueEx(hkeyCU, argv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
00069         if (!ok && hkeyLM)
00070             ok = RegQueryValueEx(hkeyLM, argv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
00071         if (!ok)
00072             regValue = -1;
00073     }
00074     if (hkeyCU)
00075         RegCloseKey(hkeyCU);
00076     if (hkeyLM)
00077         RegCloseKey(hkeyLM);
00078     if (regValue != (DWORD)-1 && regValue != (DWORD)-2)
00079         return regValue;
00080     static char msg[4048];
00081 
00082     wsprintf(msg,
00083              "%s\n\nClick Abort to exit the Application.\n"
00084              "Click Retry to Debug the Application..\n"
00085              "Click Ignore to continue running the Application.", 
00086              lpszCmdLine);
00087              
00088     return MessageBox(NULL, msg, "NSGlue_Assertion",
00089                       MB_ICONSTOP | MB_SYSTEMMODAL| 
00090                       MB_ABORTRETRYIGNORE | MB_DEFBUTTON3);
00091 }