1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla Communicator client code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1999
22 * the Initial Developer. All Rights Reserved.
25 * John Bandhauer <jband@netscape.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
48 /* MingW currently does not implement a wide version of the
49 startup routines. Workaround is to implement something like
50 it ourselves. See bug 472063 */
53 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
59 static wchar_t** __wargv
;
62 WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
63 LPSTR lpszCommandLine
, int nCmdShow
)
65 LPWSTR commandLine
= GetCommandLineW();
67 /* parse for __argc and __wargv for compatibility, since mingw
68 * doesn't claim to support it :(
70 __wargv
= CommandLineToArgvW(commandLine
, &__argc
);
74 /* need to strip off any leading whitespace plus the first argument
75 * (the executable itself) to match what should be passed to wWinMain
77 while ((*commandLine
<= L
' ') && *commandLine
) {
80 if (*commandLine
== L
'"') {
82 while ((*commandLine
!= L
'"') && *commandLine
) {
89 while (*commandLine
> L
' ') {
93 while ((*commandLine
<= L
' ') && *commandLine
) {
97 int result
= wWinMain(hInstance
, hPrevInstance
, commandLine
, nCmdShow
);
101 #endif /* __MINGW32__ */
105 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
106 LPWSTR lpszCmdLine
, int nCmdShow
)
108 /* support for auto answering based on words in the assertion.
109 * the assertion message is sent as a series of arguements (words) to the commandline.
110 * set a "word" to 0xffffffff to let the word not affect this code.
111 * set a "word" to 0xfffffffe to show the dialog.
112 * set a "word" to 0x5 to ignore (program should continue).
113 * set a "word" to 0x4 to retry (should fall into debugger).
114 * set a "word" to 0x3 to abort (die).
118 DWORD regLength
= sizeof regValue
;
120 RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\mozilla.org\\windbgdlg", 0, KEY_READ
, &hkeyCU
);
121 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\mozilla.org\\windbgdlg", 0, KEY_READ
, &hkeyLM
);
123 for (int i
= __argc
- 1; regValue
== (DWORD
)-1 && i
; --i
) {
126 ok
= RegQueryValueExW(hkeyCU
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
, ®Length
) == ERROR_SUCCESS
;
128 ok
= RegQueryValueExW(hkeyLM
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
, ®Length
) == ERROR_SUCCESS
;
136 if (regValue
!= (DWORD
)-1 && regValue
!= (DWORD
)-2)
138 static const int size
= 4096;
139 static WCHAR msg
[size
];
142 StringCchPrintfW(msg
,
147 L
"%s\n\nClick Abort to exit the Application.\n"
148 L
"Click Retry to Debug the Application.\n"
149 L
"Click Ignore to continue running the Application.",
151 msg
[size
- 1] = L
'\0';
152 return MessageBoxW(NULL
, msg
, L
"NSGlue_Assertion",
153 MB_ICONSTOP
| MB_SYSTEMMODAL
|
154 MB_ABORTRETRYIGNORE
| MB_DEFBUTTON3
);