From 073d07ac3622fa9d5228566fd2b0a9e640db603e Mon Sep 17 00:00:00 2001 From: Christoph von Wittich Date: Mon, 16 Nov 2009 01:37:12 +0000 Subject: [PATCH] partial FormatMessage wine sync svn path=/trunk/; revision=44194 --- reactos/dll/win32/kernel32/misc/errormsg.c | 73 ++++++++++++---------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/reactos/dll/win32/kernel32/misc/errormsg.c b/reactos/dll/win32/kernel32/misc/errormsg.c index 85cd334b0bc..96c4441668b 100644 --- a/reactos/dll/win32/kernel32/misc/errormsg.c +++ b/reactos/dll/win32/kernel32/misc/errormsg.c @@ -75,6 +75,42 @@ __inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str ) * Yes, ANSI strings in win32 resources. Go figure. */ +/********************************************************************** + * load_messageW (internal) + */ +static LPWSTR load_messageW( HMODULE module, UINT id, WORD lang ) +{ + PRTL_MESSAGE_RESOURCE_ENTRY mre; + WCHAR *buffer; + NTSTATUS Status; + + TRACE("module = %p, id = %08x\n", module, id ); + + if (!module) module = GetModuleHandleW( NULL ); + Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre ); + if (!NT_SUCCESS(Status)) + { + SetLastError( RtlNtStatusToDosError(Status) ); + return NULL; + } + + if (mre->Flags & MESSAGE_RESOURCE_UNICODE) + { + int len = (strlenW( (const WCHAR *)mre->Text ) + 1) * sizeof(WCHAR); + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL; + memcpy( buffer, mre->Text, len ); + } + else + { + int len = MultiByteToWideChar( CP_ACP, 0, (const char *)mre->Text, -1, NULL, 0 ); + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; + MultiByteToWideChar( CP_ACP, 0, (const char*)mre->Text, -1, buffer, len ); + } + //TRACE("returning %s\n", wine_dbgstr_w(buffer)); + return buffer; +} + + /********************************************************************** * load_messageA (internal) */ @@ -90,7 +126,10 @@ static LPSTR load_messageA( HMODULE module, UINT id, WORD lang ) if (!module) module = GetModuleHandleW( NULL ); Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre ); if (!NT_SUCCESS(Status)) + { + SetLastError( RtlNtStatusToDosError(Status) ); return NULL; + } if (mre->Flags & MESSAGE_RESOURCE_UNICODE) { @@ -109,36 +148,6 @@ static LPSTR load_messageA( HMODULE module, UINT id, WORD lang ) } - -static LPWSTR load_messageW( HMODULE module, UINT id, WORD lang ) -{ - PRTL_MESSAGE_RESOURCE_ENTRY mre; - WCHAR *buffer; - NTSTATUS Status; - - TRACE("module = %p, id = %08x\n", module, id ); - - if (!module) module = GetModuleHandleW( NULL ); - Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre ); - if (!NT_SUCCESS(Status)) - return NULL; - - if (mre->Flags & MESSAGE_RESOURCE_UNICODE) - { - int len = (strlenW( (const WCHAR *)mre->Text ) + 1) * sizeof(WCHAR); - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL; - memcpy( buffer, mre->Text, len ); - } - else - { - int len = MultiByteToWideChar( CP_ACP, 0, (const char *)mre->Text, -1, NULL, 0 ); - if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL; - MultiByteToWideChar( CP_ACP, 0, (const char*)mre->Text, -1, buffer, len ); - } - //TRACE("returning %s\n", wine_dbgstr_w(buffer)); - return buffer; -} - /*********************************************************************** * FormatMessageA (KERNEL32.@) * FIXME: missing wrap, @@ -199,7 +208,6 @@ DWORD WINAPI FormatMessageA( if (!from) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); return 0; } } @@ -457,7 +465,6 @@ DWORD WINAPI FormatMessageW( if (!from) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); return 0; } } @@ -641,7 +648,7 @@ DWORD WINAPI FormatMessageW( if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { /* nSize is the MINIMUM size */ DWORD len = strlenW(target) + 1; - *((LPVOID*)lpBuffer) = (LPVOID)LocalAlloc(LMEM_ZEROINIT,len*sizeof(WCHAR)); + *((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT,len*sizeof(WCHAR)); strcpyW(*(LPWSTR*)lpBuffer, target); } else lstrcpynW(lpBuffer, target, nSize);