ReactOS 0.4.15-dev-7788-g1ad9096
format_msg.c File Reference
#include "config.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winternl.h"
#include "winuser.h"
#include "winnls.h"
#include "wine/unicode.h"
#include "kernel_private.h"
#include "wine/debug.h"
Include dependency graph for format_msg.c:

Go to the source code of this file.

Classes

struct  format_args
 
struct  _format_message_data
 

Macros

#define WIN32_NO_STATUS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (resource)
 
static LPWSTR load_message (HMODULE module, UINT id, WORD lang)
 
static LPWSTR search_message (DWORD flags, HMODULE module, UINT id, WORD lang)
 
static ULONG_PTR get_arg (int nr, DWORD flags, struct format_args *args)
 
static LPCWSTR format_insert (BOOL unicode_caller, int insert, LPCWSTR format, DWORD flags, struct format_args *args, LPWSTR *result)
 
static void format_add_char (struct _format_message_data *fmd, WCHAR c)
 
static LPWSTR format_message (BOOL unicode_caller, DWORD dwFlags, LPCWSTR fmtstr, struct format_args *format_args)
 
DWORD WINAPI FormatMessageA (DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list *args)
 
DWORD WINAPI FormatMessageW (DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 41 of file format_msg.c.

Function Documentation

◆ format_add_char()

static void format_add_char ( struct _format_message_data fmd,
WCHAR  c 
)
static

Definition at line 313 of file format_msg.c.

314{
315 *fmd->t++ = c;
316 if (fmd->width && fmd->width != FORMAT_MESSAGE_MAX_WIDTH_MASK)
317 {
318 switch (c) {
319 case '\r':
320 case '\n':
321 fmd->space = NULL;
322 fmd->inspace = FALSE;
323 fmd->w = 0;
324 break;
325 case ' ':
326 if (!fmd->inspace)
327 fmd->space = fmd->t - 1;
328 fmd->inspace = TRUE;
329 fmd->w++;
330 break;
331 default:
332 fmd->inspace = FALSE;
333 fmd->w++;
334 }
335 if (fmd->w == fmd->width) {
336 LPWSTR notspace;
337 if (fmd->space) {
338 notspace = fmd->space;
339 while (notspace != fmd->t && *notspace == ' ')
340 notspace++;
341 } else
342 notspace = fmd->space = fmd->t;
343 fmd->w = fmd->t - notspace;
344 memmove(fmd->space+2, notspace, fmd->w * sizeof(*fmd->t));
345 *fmd->space++ = '\r';
346 *fmd->space++ = '\n';
347 fmd->t = fmd->space + fmd->w;
348 fmd->space = NULL;
349 fmd->inspace = FALSE;
350 }
351 }
352 if ((DWORD)(fmd->t - fmd->formatted) == fmd->size) {
353 DWORD_PTR ispace = fmd->space - fmd->formatted;
354 /* Allocate two extra characters so we can insert a '\r\n' in
355 * the middle of a word.
356 */
357 fmd->formatted = HeapReAlloc(GetProcessHeap(), 0, fmd->formatted, (fmd->size * 2 + 2) * sizeof(WCHAR));
358 fmd->t = fmd->formatted + fmd->size;
359 if (fmd->space)
360 fmd->space = fmd->formatted + ispace;
361 fmd->size *= 2;
362 }
363}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapReAlloc
Definition: compat.h:734
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define FORMAT_MESSAGE_MAX_WIDTH_MASK
Definition: winbase.h:425
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by format_message().

◆ format_insert()

static LPCWSTR format_insert ( BOOL  unicode_caller,
int  insert,
LPCWSTR  format,
DWORD  flags,
struct format_args args,
LPWSTR result 
)
static

Definition at line 165 of file format_msg.c.

168{
169 static const WCHAR fmt_u[] = {'%','u',0};
170 WCHAR *wstring = NULL, *p, fmt[256];
172 int size;
173
174 if (*format != '!') /* simple string */
175 {
176 arg = get_arg( insert, flags, args );
177 if (unicode_caller || !arg)
178 {
179 static const WCHAR nullW[] = {'(','n','u','l','l',')',0};
180 const WCHAR *str = (const WCHAR *)arg;
181
182 if (!str) str = nullW;
183 *result = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(WCHAR) );
184 strcpyW( *result, str );
185 }
186 else
187 {
188 const char *str = (const char *)arg;
190 *result = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
192 }
193 return format;
194 }
195
196 format++;
197 p = fmt;
198 *p++ = '%';
199
200 while (*format == '0' ||
201 *format == '+' ||
202 *format == '-' ||
203 *format == ' ' ||
204 *format == '*' ||
205 *format == '#')
206 {
207 if (*format == '*')
208 {
209 p += sprintfW( p, fmt_u, get_arg( insert, flags, args ));
210 insert = -1;
211 format++;
212 }
213 else *p++ = *format++;
214 }
215 while (isdigitW(*format)) *p++ = *format++;
216
217 if (*format == '.')
218 {
219 *p++ = *format++;
220 if (*format == '*')
221 {
222 p += sprintfW( p, fmt_u, get_arg( insert, flags, args ));
223 insert = -1;
224 format++;
225 }
226 else
227 while (isdigitW(*format)) *p++ = *format++;
228 }
229
230 /* replicate MS bug: drop an argument when using va_list with width/precision */
231 if (insert == -1 && args->list) args->last--;
232 arg = get_arg( insert, flags, args );
233
234 /* check for ascii string format */
235 if ((format[0] == 'h' && format[1] == 's') ||
236 (format[0] == 'h' && format[1] == 'S') ||
237 (unicode_caller && format[0] == 'S') ||
238 (!unicode_caller && format[0] == 's'))
239 {
240 DWORD len = MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, NULL, 0 );
241 wstring = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
242 MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, wstring, len );
243 arg = (ULONG_PTR)wstring;
244 *p++ = 's';
245 }
246 /* check for ascii character format */
247 else if ((format[0] == 'h' && format[1] == 'c') ||
248 (format[0] == 'h' && format[1] == 'C') ||
249 (unicode_caller && format[0] == 'C') ||
250 (!unicode_caller && format[0] == 'c'))
251 {
252 char ch = arg;
253 wstring = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(WCHAR) );
254 MultiByteToWideChar( CP_ACP, 0, &ch, 1, wstring, 1 );
255 wstring[1] = 0;
256 arg = (ULONG_PTR)wstring;
257 *p++ = 's';
258 }
259 /* check for wide string format */
260 else if ((format[0] == 'l' && format[1] == 's') ||
261 (format[0] == 'l' && format[1] == 'S') ||
262 (format[0] == 'w' && format[1] == 's') ||
263 (!unicode_caller && format[0] == 'S'))
264 {
265 *p++ = 's';
266 }
267 /* check for wide character format */
268 else if ((format[0] == 'l' && format[1] == 'c') ||
269 (format[0] == 'l' && format[1] == 'C') ||
270 (format[0] == 'w' && format[1] == 'c') ||
271 (!unicode_caller && format[0] == 'C'))
272 {
273 *p++ = 'c';
274 }
275 /* FIXME: handle I64 etc. */
276 else while (*format && *format != '!') *p++ = *format++;
277
278 *p = 0;
279 size = 256;
280 for (;;)
281 {
282 WCHAR *ret = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
283 int needed = snprintfW( ret, size, fmt, arg );
284 if (needed == -1 || needed >= size)
285 {
286 HeapFree( GetProcessHeap(), 0, ret );
287 size = max( needed + 1, size * 2 );
288 }
289 else
290 {
291 *result = ret;
292 break;
293 }
294 }
295
296 while (*format && *format != '!') format++;
297 if (*format == '!') format++;
298
299 HeapFree( GetProcessHeap(), 0, wstring );
300 return format;
301}
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
static ULONG_PTR get_arg(int nr, DWORD flags, struct format_args *args)
Definition: format_msg.c:149
#define ULONG_PTR
Definition: config.h:101
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
static const WCHAR nullW[]
Definition: json.c:32
#define isdigitW(n)
Definition: unicode.h:50
#define strlenW(s)
Definition: unicode.h:28
#define snprintfW
Definition: unicode.h:60
#define sprintfW
Definition: unicode.h:58
#define strcpyW(d, s)
Definition: unicode.h:29
const WCHAR * str
Definition: match.c:390
Definition: dsound.c:943
#define max(a, b)
Definition: svc.c:63
uint32_t ULONG_PTR
Definition: typedefs.h:65
int ret
void * arg
Definition: msvc.h:10
static int insert
Definition: xmllint.c:138

Referenced by format_message().

◆ format_message()

static LPWSTR format_message ( BOOL  unicode_caller,
DWORD  dwFlags,
LPCWSTR  fmtstr,
struct format_args format_args 
)
static

Definition at line 368 of file format_msg.c.

370{
371 struct _format_message_data fmd;
372 LPCWSTR f;
373 BOOL eos = FALSE;
374
375 fmd.size = 100;
376 fmd.formatted = fmd.t = HeapAlloc( GetProcessHeap(), 0, (fmd.size + 2) * sizeof(WCHAR) );
377
379 fmd.w = 0;
380 fmd.inspace = FALSE;
381 fmd.space = NULL;
382 f = fmtstr;
383 while (*f && !eos) {
384 if (*f=='%') {
385 int insertnr;
386 WCHAR *str,*x;
387
388 f++;
389 switch (*f) {
390 case '1':case '2':case '3':case '4':case '5':
391 case '6':case '7':case '8':case '9':
393 goto ignore_inserts;
396 {
398 HeapFree(GetProcessHeap(), 0, fmd.formatted);
399 return NULL;
400 }
401 insertnr = *f-'0';
402 switch (f[1]) {
403 case '0':case '1':case '2':case '3':
404 case '4':case '5':case '6':case '7':
405 case '8':case '9':
406 f++;
407 insertnr = insertnr*10 + *f-'0';
408 f++;
409 break;
410 default:
411 f++;
412 break;
413 }
414 f = format_insert( unicode_caller, insertnr, f, dwFlags, format_args, &str );
415 for (x = str; *x; x++) format_add_char(&fmd, *x);
416 HeapFree( GetProcessHeap(), 0, str );
417 break;
418 case 'n':
419 format_add_char(&fmd, '\r');
420 format_add_char(&fmd, '\n');
421 f++;
422 break;
423 case 'r':
424 format_add_char(&fmd, '\r');
425 f++;
426 break;
427 case 't':
428 format_add_char(&fmd, '\t');
429 f++;
430 break;
431 case '0':
432 eos = TRUE;
433 f++;
434 break;
435 case '\0':
437 HeapFree(GetProcessHeap(), 0, fmd.formatted);
438 return NULL;
439 ignore_inserts:
440 default:
442 format_add_char(&fmd, '%');
443 format_add_char(&fmd, *f++);
444 break;
445 }
446 } else {
447 WCHAR ch = *f;
448 f++;
449 if (ch == '\r') {
450 if (*f == '\n')
451 f++;
452 if(fmd.width)
453 format_add_char(&fmd, ' ');
454 else
455 {
456 format_add_char(&fmd, '\r');
457 format_add_char(&fmd, '\n');
458 }
459 } else {
460 if (ch == '\n')
461 {
462 if(fmd.width)
463 format_add_char(&fmd, ' ');
464 else
465 {
466 format_add_char(&fmd, '\r');
467 format_add_char(&fmd, '\n');
468 }
469 }
470 else
471 format_add_char(&fmd, ch);
472 }
473 }
474 }
475 *fmd.t = '\0';
476
477 return fmd.formatted;
478}
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
static LPCWSTR format_insert(BOOL unicode_caller, int insert, LPCWSTR format, DWORD flags, struct format_args *args, LPWSTR *result)
Definition: format_msg.c:165
static void format_add_char(struct _format_message_data *fmd, WCHAR c)
Definition: format_msg.c:313
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83
__ms_va_list * list
Definition: format_msg.c:59
ULONG_PTR * args
Definition: format_msg.c:58
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:424
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by FormatMessageA(), and FormatMessageW().

◆ FormatMessageA()

DWORD WINAPI FormatMessageA ( DWORD  dwFlags,
LPCVOID  lpSource,
DWORD  dwMessageId,
DWORD  dwLanguageId,
LPSTR  lpBuffer,
DWORD  nSize,
__ms_va_list args 
)

Definition at line 483 of file format_msg.c.

491{
493 DWORD ret = 0;
495 DWORD destlength;
496 LPWSTR from;
497
498 TRACE("(0x%x,%p,%d,0x%x,%p,%d,%p)\n",
499 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
500
502 {
503 if (!lpBuffer)
504 {
506 return 0;
507 }
508 else
509 *(LPSTR *)lpBuffer = NULL;
510 }
511
513 {
516 format_args.last = 0;
517 }
518 else
519 {
522 format_args.last = 0;
523 }
524
525 from = NULL;
527 {
528 DWORD length = MultiByteToWideChar(CP_ACP, 0, lpSource, -1, NULL, 0);
529 from = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
530 MultiByteToWideChar(CP_ACP, 0, lpSource, -1, from, length);
531 }
533 {
534 from = search_message( dwFlags, (HMODULE)lpSource, dwMessageId, dwLanguageId );
535 if (!from) return 0;
536 }
537 else
538 {
540 return 0;
541 }
542
544 if (!target)
545 goto failure;
546
547 TRACE("-- %s\n", debugstr_w(target));
548
549 /* Only try writing to an output buffer if there are processed characters
550 * in the temporary output buffer. */
551 if (*target)
552 {
553 destlength = WideCharToMultiByte(CP_ACP, 0, target, -1, NULL, 0, NULL, NULL);
555 {
556 LPSTR buf = LocalAlloc(LMEM_ZEROINIT, max(nSize, destlength));
557 WideCharToMultiByte(CP_ACP, 0, target, -1, buf, destlength, NULL, NULL);
558 *((LPSTR*)lpBuffer) = buf;
559 }
560 else
561 {
562 if (nSize < destlength)
563 {
565 goto failure;
566 }
567 WideCharToMultiByte(CP_ACP, 0, target, -1, lpBuffer, destlength, NULL, NULL);
568 }
569 ret = destlength - 1; /* null terminator */
570 }
571
572failure:
576 TRACE("-- returning %u\n", ret);
577 return ret;
578}
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define WideCharToMultiByte
Definition: compat.h:111
static LPWSTR format_message(BOOL unicode_caller, DWORD dwFlags, LPCWSTR fmtstr, struct format_args *format_args)
Definition: format_msg.c:368
static LPWSTR search_message(DWORD flags, HMODULE module, UINT id, WORD lang)
Definition: format_msg.c:128
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum target
Definition: glext.h:7315
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
#define debugstr_w
Definition: kernel32.h:32
#define args
Definition: format.c:66
#define TRACE(s)
Definition: solgame.cpp:4
CardRegion * from
Definition: spigame.cpp:19
#define LMEM_ZEROINIT
Definition: winbase.h:375
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:422
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2084
char * LPSTR
Definition: xmlstorage.h:182

Referenced by doit(), error(), ATL::ChTraitsCRT< char >::FormatMessageV(), CVfdShExt::GetCommandString(), OutputError(), ReportLastError(), ShellMessageBoxA(), test_format_message(), test_message_allocate_buffer(), test_message_from_hmodule(), test_message_from_string(), test_message_ignore_inserts(), test_message_insufficient_buffer(), test_message_invalid_flags(), test_message_null_buffer(), test_message_wrap(), and TestDceErrorInqText().

◆ FormatMessageW()

DWORD WINAPI FormatMessageW ( DWORD  dwFlags,
LPCVOID  lpSource,
DWORD  dwMessageId,
DWORD  dwLanguageId,
LPWSTR  lpBuffer,
DWORD  nSize,
__ms_va_list args 
)

Definition at line 583 of file format_msg.c.

591{
593 DWORD ret = 0;
595 DWORD talloced;
596 LPWSTR from;
597
598 TRACE("(0x%x,%p,%d,0x%x,%p,%d,%p)\n",
599 dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
600
601 if (!lpBuffer)
602 {
604 return 0;
605 }
606
608 *(LPWSTR *)lpBuffer = NULL;
609
611 {
614 format_args.last = 0;
615 }
616 else
617 {
620 format_args.last = 0;
621 }
622
623 from = NULL;
625 from = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpSource) + 1) *
626 sizeof(WCHAR) );
627 strcpyW( from, lpSource );
628 }
630 {
631 from = search_message( dwFlags, (HMODULE)lpSource, dwMessageId, dwLanguageId );
632 if (!from) return 0;
633 }
634 else
635 {
637 return 0;
638 }
639
641 if (!target)
642 goto failure;
643
644 talloced = strlenW(target)+1;
645 TRACE("-- %s\n",debugstr_w(target));
646
647 /* Only allocate a buffer if there are processed characters in the
648 * temporary output buffer. If a caller supplies the buffer, then
649 * a null terminator will be written to it. */
651 {
652 if (*target)
653 {
654 /* nSize is the MINIMUM size */
655 *((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT, max(nSize, talloced)*sizeof(WCHAR));
657 }
658 }
659 else
660 {
661 if (nSize < talloced)
662 {
664 goto failure;
665 }
667 }
668
669 ret = talloced - 1; /* null terminator */
670failure:
674 TRACE("-- returning %u\n", ret);
675 return ret;
676}

Referenced by _SetOperationTexts(), build_systeminfo_tree(), CFn_WMCommand(), CheckForError(), cmdHelpMsg(), ConMsgPrintf2V(), ConMsgPuts(), DceErrorInqTextW(), DisplayError(), DisplayWin32Error(), dlg_win32error(), do_error_dialog(), doitW(), ErrorMessageBox(), export_validate_filename(), field_format_public_key(), format_message(), FormatMessageBox(), FormatMessageSafeW(), ATL::ChTraitsCRT< _CharType >::FormatMessageV(), FormatString(), get_file_handle(), CVfdShExt::GetCommandString(), GetCountryFromCountryCode(), GetError(), GetLastErrorText(), GetMessageStringFromDll(), import_validate_filename(), last_error::last_error(), LoadAndFormatString(), LoadAndFormatStringsCat(), LogToFile(), ntstatus_error::ntstatus_error(), OleUIAddVerbMenuW(), output_formatstring(), OutputText(), ParseLogonHours(), PRINTDLG_UpdatePrintDlgW(), PrintError(), PrintErrorMessage(), PrintErrorText(), PrintMessageString(), PrintMessageStringV(), PrintNetMessage(), PrintPaddedMessageString(), PrintWin32Error(), promptdisk_init(), SHELL_ConfirmDialogW(), ShellMessageBoxW(), ShellMessageBoxWrapW(), ShowError(), CZipExtract::ShowExtractError(), ShowItemError(), ShowLastError(), ShowLastWin32Error(), ShowOutOfMemory(), ShowStepError(), ShowWin32Error(), START_TEST(), StatusBarLoadAndFormatString(), taskkill_vprintfW(), test_message_allocate_buffer_wide(), test_message_from_string_wide(), test_message_ignore_inserts_wide(), test_message_insufficient_buffer_wide(), test_message_invalid_flags_wide(), test_message_null_buffer_wide(), VarListLoadAndFormatString(), XCOPY_FailMessage(), and XCOPY_wprintf().

◆ get_arg()

static ULONG_PTR get_arg ( int  nr,
DWORD  flags,
struct format_args args 
)
static

Definition at line 149 of file format_msg.c.

150{
151 if (nr == -1) nr = args->last + 1;
152 if (args->list)
153 {
154 if (!args->args) args->args = HeapAlloc( GetProcessHeap(), 0, 99 * sizeof(ULONG_PTR) );
155 while (nr > args->last)
156 args->args[args->last++] = va_arg( *args->list, ULONG_PTR );
157 }
158 if (nr > args->last) args->last = nr;
159 return args->args[nr - 1];
160}
#define va_arg(ap, T)
Definition: acmsvcex.h:89
ULONG nr
Definition: thread.c:7

Referenced by array_access(), exec_script(), and format_insert().

◆ load_message()

static LPWSTR load_message ( HMODULE  module,
UINT  id,
WORD  lang 
)
static

Definition at line 88 of file format_msg.c.

89{
90#ifdef __REACTOS__
92#else
93 const MESSAGE_RESOURCE_ENTRY *mre;
94#endif
97
98 TRACE("module = %p, id = %08x\n", module, id );
99
101#ifdef __REACTOS__
103 if (!NT_SUCCESS(status))
104#else
106#endif
107 {
109 return NULL;
110 }
111
113 {
114 int len = (strlenW( (const WCHAR *)mre->Text ) + 1) * sizeof(WCHAR);
115 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
116 memcpy( buffer, mre->Text, len );
117 }
118 else
119 {
120 int len = MultiByteToWideChar( CP_ACP, 0, (const char *)mre->Text, -1, NULL, 0 );
121 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
122 MultiByteToWideChar( CP_ACP, 0, (const char*)mre->Text, -1, buffer, len );
123 }
124 TRACE("returning %s\n", wine_dbgstr_w(buffer));
125 return buffer;
126}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
GLuint buffer
Definition: glext.h:5915
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define wine_dbgstr_w
Definition: kernel32.h:34
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
NTSYSAPI NTSTATUS NTAPI RtlFindMessage(_In_ PVOID BaseAddress, _In_ ULONG Type, _In_ ULONG Language, _In_ ULONG MessageId, _Out_ PMESSAGE_RESOURCE_ENTRY *MessageResourceEntry)
#define MESSAGE_RESOURCE_UNICODE
Definition: rtltypes.h:351
#define RT_MESSAGETABLE
Definition: pedump.c:373
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: rtltypes.h:1896
UCHAR Text[ANYSIZE_ARRAY]
Definition: rtltypes.h:1899
USHORT Flags
Definition: rtltypes.h:1898
Definition: ps.c:97
static const WCHAR lang[]
Definition: wbemdisp.c:287

Referenced by search_message().

◆ search_message()

static LPWSTR search_message ( DWORD  flags,
HMODULE  module,
UINT  id,
WORD  lang 
)
static

Definition at line 128 of file format_msg.c.

129{
130 LPWSTR from = NULL;
132 from = load_message( module, id, lang );
134 {
135 /* Fold win32 hresult to its embedded error code. */
136 if (HRESULT_SEVERITY(id) == SEVERITY_ERROR &&
138 {
139 id = HRESULT_CODE(id);
140 }
142 }
143 return from;
144}
HMODULE kernel32_handle
Definition: dllmain.c:26
static LPWSTR load_message(HMODULE module, UINT id, WORD lang)
Definition: format_msg.c:88
#define HRESULT_FACILITY(hr)
Definition: winerror.h:79
#define HRESULT_SEVERITY(hr)
Definition: winerror.h:82
#define SEVERITY_ERROR
Definition: winerror.h:65
#define FACILITY_WIN32
Definition: winerror.h:27
#define HRESULT_CODE(hr)
Definition: winerror.h:76

Referenced by FormatMessageA(), and FormatMessageW().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( resource  )