1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 */
18 # include <shellapi.h>
19 int WINAPI
wWinMain(HINSTANCE
, HINSTANCE
, LPWSTR
, int);
25 static wchar_t** __wargv
;
27 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
28 LPSTR lpszCommandLine
, int nCmdShow
) {
29 LPWSTR commandLine
= GetCommandLineW();
31 /* parse for __argc and __wargv for compatibility, since mingw
32 * doesn't claim to support it :(
34 __wargv
= CommandLineToArgvW(commandLine
, &__argc
);
35 if (!__wargv
) return 127;
37 /* need to strip off any leading whitespace plus the first argument
38 * (the executable itself) to match what should be passed to wWinMain
40 while ((*commandLine
<= L
' ') && *commandLine
) {
43 if (*commandLine
== L
'"') {
45 while ((*commandLine
!= L
'"') && *commandLine
) {
52 while (*commandLine
> L
' ') {
56 while ((*commandLine
<= L
' ') && *commandLine
) {
60 int result
= wWinMain(hInstance
, hPrevInstance
, commandLine
, nCmdShow
);
64 #endif /* __MINGW32__ */
66 int WINAPI
wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
67 LPWSTR lpszCmdLine
, int nCmdShow
) {
68 /* support for auto answering based on words in the assertion.
69 * the assertion message is sent as a series of arguements (words) to the
70 * commandline. set a "word" to 0xffffffff to let the word not affect this
71 * code. set a "word" to 0xfffffffe to show the dialog. set a "word" to 0x5 to
72 * ignore (program should continue). set a "word" to 0x4 to retry (should fall
73 * into debugger). set a "word" to 0x3 to abort (die).
77 DWORD regLength
= sizeof regValue
;
79 RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\mozilla.org\\windbgdlg", 0,
81 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\mozilla.org\\windbgdlg", 0,
83 for (int i
= __argc
- 1; regValue
== (DWORD
)-1 && i
; --i
) {
86 ok
= RegQueryValueExW(hkeyCU
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
,
87 ®Length
) == ERROR_SUCCESS
;
89 ok
= RegQueryValueExW(hkeyLM
, __wargv
[i
], 0, ®Type
, (LPBYTE
)®Value
,
90 ®Length
) == ERROR_SUCCESS
;
91 if (!ok
) regValue
= -1;
93 if (hkeyCU
) RegCloseKey(hkeyCU
);
94 if (hkeyLM
) RegCloseKey(hkeyLM
);
95 if (regValue
!= (DWORD
)-1 && regValue
!= (DWORD
)-2) return regValue
;
96 static const int size
= 4096;
97 static WCHAR msg
[size
];
100 StringCchPrintfW(msg
,
105 L
"%s\n\nClick Abort to exit the Application.\n"
106 L
"Click Retry to Debug the Application.\n"
107 L
"Click Ignore to continue running the Application.",
109 msg
[size
- 1] = L
'\0';
111 nullptr, msg
, L
"NSGlue_Assertion",
112 MB_ICONSTOP
| MB_SYSTEMMODAL
| MB_ABORTRETRYIGNORE
| MB_DEFBUTTON3
);