@@ -178,22 +178,43 @@ public static void closeHandle(HANDLE h) {
178
178
}
179
179
}
180
180
181
+ /**
182
+ * Format a message from a code.
183
+ *
184
+ * @param code The error code
185
+ * @return Formatted message in the default locale.
186
+ */
187
+ public static String formatMessage (int code ) {
188
+ return formatMessage (code , 0 , 0 );
189
+ }
190
+
181
191
/**
182
192
* Format a message from the value obtained from
183
193
* {@link Kernel32#GetLastError()} or {@link Native#getLastError()}.
184
194
*
195
+ * <p>If you pass in zero, FormatMessage looks for a message for LANGIDs in the following order:</p>
196
+ * <ol>
197
+ * <li>Language neutral</li>
198
+ * <li>Thread LANGID, based on the thread's locale value</li>
199
+ * <li>User default LANGID, based on the user's default locale value</li>
200
+ * <li>System default LANGID, based on the system default locale value</li>
201
+ * <li>US English</li>
202
+ * </ol>
203
+ *
185
204
* @param code The error code
186
- * @return Formatted message.
205
+ * @param primaryLangId The primary language identifier
206
+ * @param sublangId The sublanguage identifier
207
+ * @return Formatted message in the specified locale.
187
208
*/
188
- public static String formatMessage (int code ) {
209
+ public static String formatMessage (int code , int primaryLangId , int sublangId ) {
189
210
PointerByReference buffer = new PointerByReference ();
190
211
int nLen = Kernel32 .INSTANCE .FormatMessage (
191
212
WinBase .FORMAT_MESSAGE_ALLOCATE_BUFFER
192
213
| WinBase .FORMAT_MESSAGE_FROM_SYSTEM
193
214
| WinBase .FORMAT_MESSAGE_IGNORE_INSERTS ,
194
215
null ,
195
216
code ,
196
- 0 , // TODO: // MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
217
+ WinNT . LocaleMacros . MAKELANGID (primaryLangId , sublangId ),
197
218
buffer , 0 , null );
198
219
if (nLen == 0 ) {
199
220
throw new LastErrorException (Native .getLastError ());
0 commit comments