| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | //***************************************************************************** |
| 5 | // EEMessageBox.h |
| 6 | // |
| 7 | |
| 8 | // |
| 9 | // This module contains the implementation for the message box utility code for |
| 10 | // use inside the Execution Engine. These APIs ensure the GC mode is properly |
| 11 | // toggled to preemptive before the dialog is displayed. |
| 12 | // |
| 13 | //***************************************************************************** |
| 14 | |
| 15 | #include "common.h" |
| 16 | #include "eemessagebox.h" |
| 17 | |
| 18 | // Undef these so we can call them from the EE versions. |
| 19 | #undef UtilMessageBoxCatastrophicVA |
| 20 | #undef UtilMessageBoxVA |
| 21 | #undef UtilMessageBoxNonLocalizedVA |
| 22 | |
| 23 | int EEMessageBoxCatastrophicVA( |
| 24 | UINT uText, // Text for MessageBox |
| 25 | UINT uTitle, // Title for MessageBox |
| 26 | UINT uType, // Style of MessageBox |
| 27 | BOOL showFileNameInTitle, // Flag to show FileName in Caption |
| 28 | va_list insertionArgs) // Additional Arguments |
| 29 | { |
| 30 | CONTRACTL |
| 31 | { |
| 32 | MODE_ANY; |
| 33 | GC_NOTRIGGER; |
| 34 | NOTHROW; |
| 35 | } |
| 36 | CONTRACTL_END; |
| 37 | |
| 38 | return UtilMessageBoxCatastrophicVA(uText, uTitle, uType, showFileNameInTitle, insertionArgs); |
| 39 | } |
| 40 | |
| 41 | int EEMessageBoxCatastrophic( |
| 42 | UINT uText, // Text for MessageBox |
| 43 | UINT uTitle, // Title for MessageBox |
| 44 | ...) // Additional Arguments |
| 45 | { |
| 46 | CONTRACTL |
| 47 | { |
| 48 | MODE_ANY; |
| 49 | GC_NOTRIGGER; |
| 50 | NOTHROW; |
| 51 | } |
| 52 | CONTRACTL_END; |
| 53 | |
| 54 | va_list marker; |
| 55 | va_start(marker, uTitle); |
| 56 | |
| 57 | int result = EEMessageBoxCatastrophicVA(uText, uTitle, MB_OK | MB_ICONERROR, TRUE, marker); |
| 58 | va_end( marker ); |
| 59 | |
| 60 | return result; |
| 61 | } |
| 62 | |
| 63 | int EEMessageBoxCatastrophicWithCustomizedStyle( |
| 64 | UINT uText, // Text for MessageBox |
| 65 | UINT uTitle, // Title for MessageBox |
| 66 | UINT uType, // Style of MessageBox |
| 67 | BOOL showFileNameInTitle, // Flag to show FileName in Caption |
| 68 | ...) // Additional Arguments |
| 69 | { |
| 70 | CONTRACTL |
| 71 | { |
| 72 | MODE_ANY; |
| 73 | GC_NOTRIGGER; |
| 74 | NOTHROW; |
| 75 | } |
| 76 | CONTRACTL_END; |
| 77 | |
| 78 | va_list marker; |
| 79 | va_start(marker, showFileNameInTitle); |
| 80 | |
| 81 | int result = EEMessageBoxCatastrophicVA(uText, uTitle, uType, showFileNameInTitle, marker); |
| 82 | va_end( marker ); |
| 83 | |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | #ifdef _DEBUG |
| 88 | |
| 89 | int EEMessageBoxNonLocalizedDebugOnly( |
| 90 | LPCWSTR lpText, // Text message |
| 91 | LPCWSTR lpTitle, // Caption |
| 92 | UINT uType, // Style of MessageBox |
| 93 | ... ) // Additional Arguments |
| 94 | { |
| 95 | CONTRACTL |
| 96 | { |
| 97 | MODE_ANY; |
| 98 | GC_TRIGGERS; |
| 99 | NOTHROW; |
| 100 | } |
| 101 | CONTRACTL_END; |
| 102 | |
| 103 | GCX_PREEMP(); |
| 104 | |
| 105 | va_list marker; |
| 106 | va_start(marker, uType); |
| 107 | |
| 108 | int result = UtilMessageBoxNonLocalizedVA(NULL, lpText, lpTitle, uType, FALSE, TRUE, NULL, marker); |
| 109 | va_end( marker ); |
| 110 | |
| 111 | return result; |
| 112 | } |
| 113 | |
| 114 | #endif // _DEBUG |
| 115 | |
| 116 | // If we didn't display a dialog to the user, this method returns IDIGNORE, unlike the others that return IDABORT. |
| 117 | int EEMessageBoxNonLocalizedNonFatal( |
| 118 | LPCWSTR lpText, // Text message |
| 119 | LPCWSTR lpTitle, // Caption |
| 120 | UINT uType, // Style of MessageBox |
| 121 | ... ) // Additional Arguments |
| 122 | { |
| 123 | CONTRACTL |
| 124 | { |
| 125 | MODE_ANY; |
| 126 | GC_TRIGGERS; |
| 127 | NOTHROW; |
| 128 | } |
| 129 | CONTRACTL_END; |
| 130 | |
| 131 | GCX_PREEMP(); |
| 132 | |
| 133 | va_list marker; |
| 134 | va_start(marker, uType); |
| 135 | BOOL inputFromUser = FALSE; |
| 136 | |
| 137 | int result = UtilMessageBoxNonLocalizedVA(NULL, lpText, lpTitle, NULL, uType, FALSE, TRUE, &inputFromUser, marker); |
| 138 | va_end( marker ); |
| 139 | |
| 140 | if (inputFromUser == FALSE && result == IDABORT) |
| 141 | result = IDIGNORE; |
| 142 | |
| 143 | return result; |
| 144 | } |
| 145 | |
| 146 | // If we didn't display a dialog to the user, this method returns IDIGNORE, unlike the others that return IDABORT. |
| 147 | int EEMessageBoxNonLocalizedNonFatal( |
| 148 | LPCWSTR lpText, // Text message |
| 149 | LPCWSTR lpTitle, // Caption |
| 150 | LPCWSTR lpDetails,// Detailed message like a stack trace |
| 151 | UINT uType, // Style of MessageBox |
| 152 | ... ) // Additional Arguments |
| 153 | { |
| 154 | CONTRACTL |
| 155 | { |
| 156 | MODE_ANY; |
| 157 | GC_TRIGGERS; |
| 158 | NOTHROW; |
| 159 | } |
| 160 | CONTRACTL_END; |
| 161 | |
| 162 | GCX_PREEMP(); |
| 163 | |
| 164 | va_list marker; |
| 165 | va_start(marker, uType); |
| 166 | BOOL inputFromUser = FALSE; |
| 167 | |
| 168 | int result = UtilMessageBoxNonLocalizedVA(NULL, lpText, lpTitle, lpDetails, uType, FALSE, TRUE, &inputFromUser, marker); |
| 169 | va_end( marker ); |
| 170 | |
| 171 | if (inputFromUser == FALSE && result == IDABORT) |
| 172 | result = IDIGNORE; |
| 173 | |
| 174 | return result; |
| 175 | } |
| 176 | |
| 177 | // Redefine these to errors just in case code is added after this point in the file. |
| 178 | #define UtilMessageBoxCatastrophicVA __error("Use one of the EEMessageBox APIs (defined in eemessagebox.h) from inside the EE") |
| 179 | #define UtilMessageBoxVA __error("Use one of the EEMessageBox APIs (defined in eemessagebox.h) from inside the EE") |
| 180 | #define UtilMessageBoxNonLocalizedVA __error("Use one of the EEMessageBox APIs (defined in eemessagebox.h) from inside the EE") |
| 181 | |
| 182 | |