1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
14 /* MingW currently does not implement a wide version of the
15 startup routines. Workaround is to implement something like
16 it ourselves. See bug 472063 */
19 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
25 static wchar_t** __wargv
;
28 WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
29 LPSTR lpszCommandLine
, int nCmdShow
)
31 LPWSTR commandLine
= GetCommandLineW();
33 /* parse for __argc and __wargv for compatibility, since mingw
34 * doesn't claim to support it :(
36 __wargv
= CommandLineToArgvW(commandLine
, &__argc
);
40 /* need to strip off any leading whitespace plus the first argument
41 * (the executable itself) to match what should be passed to wWinMain
43 while ((*commandLine
<= L
' ') && *commandLine
) {
46 if (*commandLine
== L
'"') {
48 while ((*commandLine
!= L
'"') && *commandLine
) {
55 while (*commandLine
> L
' ') {
59 while ((*commandLine
<= L
' ') && *commandLine
) {
63 int result
= wWinMain(hInstance
, hPrevInstance
, commandLine
, nCmdShow
);
67 #endif /* __MINGW32__ */
71 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
72 LPWSTR lpszCmdLine
, int nCmdShow
)
74 /* support for auto answering based on words in the assertion.
75 * the assertion message is sent as a series of arguements (words) to the commandline.
76 * set a "word" to 0xffffffff to let the word not affect this code.
77 * set a "word" to 0xfffffffe to show the dialog.
78 * set a "word" to 0x5 to ignore (program should continue).
79 * set a "word" to 0x4 to retry (should fall into debugger).
80 * set a "word" to 0x3 to abort (die).
84 DWORD regLength
= sizeof regValue
;
86 RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\mozilla.org\\windbgdlg", 0, KEY_READ
, &hkeyCU
);
87 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\mozilla.org\\windbgdlg", 0, KEY_READ
, &hkeyLM
);
89 for (int i
= __argc
- 1; regValue
== (DWORD
)-1 && i
; --i
) {
92 ok
= RegQueryValueExW(hkeyCU
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
, ®Length
) == ERROR_SUCCESS
;
94 ok
= RegQueryValueExW(hkeyLM
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
, ®Length
) == ERROR_SUCCESS
;
102 if (regValue
!= (DWORD
)-1 && regValue
!= (DWORD
)-2)
104 static const int size
= 4096;
105 static WCHAR msg
[size
];
108 StringCchPrintfW(msg
,
113 L
"%s\n\nClick Abort to exit the Application.\n"
114 L
"Click Retry to Debug the Application.\n"
115 L
"Click Ignore to continue running the Application.",
117 msg
[size
- 1] = L
'\0';
118 return MessageBoxW(nullptr, msg
, L
"NSGlue_Assertion",
119 MB_ICONSTOP
| MB_SYSTEMMODAL
|
120 MB_ABORTRETRYIGNORE
| MB_DEFBUTTON3
);