Alexandre Julliard : kernel32: Propagate the error result from RtlFindMessage in FormatMessage.

Alexandre Julliard julliard at winehq.org
Fri Oct 30 11:04:29 CDT 2009


Module: wine
Branch: master
Commit: 100131d4ca7c409ef0fc940def01f0593a75cc75
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=100131d4ca7c409ef0fc940def01f0593a75cc75

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Oct 29 17:40:15 2009 +0100

kernel32: Propagate the error result from RtlFindMessage in FormatMessage.

---

 dlls/kernel32/format_msg.c       |   28 ++++++++++++++--------------
 dlls/kernel32/tests/format_msg.c |    8 ++++----
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/dlls/kernel32/format_msg.c b/dlls/kernel32/format_msg.c
index 18b4f96..46f65a1 100644
--- a/dlls/kernel32/format_msg.c
+++ b/dlls/kernel32/format_msg.c
@@ -72,11 +72,16 @@ static LPWSTR load_messageW( HMODULE module, UINT id, WORD lang )
 {
     const MESSAGE_RESOURCE_ENTRY *mre;
     WCHAR *buffer;
+    NTSTATUS status;
 
     TRACE("module = %p, id = %08x\n", module, id );
 
     if (!module) module = GetModuleHandleW( NULL );
-    if (RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre ) != STATUS_SUCCESS) return NULL;
+    if ((status = RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre )) != STATUS_SUCCESS)
+    {
+        SetLastError( RtlNtStatusToDosError(status) );
+        return NULL;
+    }
 
     if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
     {
@@ -102,11 +107,16 @@ static LPSTR load_messageA( HMODULE module, UINT id, WORD lang )
 {
     const MESSAGE_RESOURCE_ENTRY *mre;
     char *buffer;
+    NTSTATUS status;
 
     TRACE("module = %p, id = %08x\n", module, id );
 
     if (!module) module = GetModuleHandleW( NULL );
-    if (RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre ) != STATUS_SUCCESS) return NULL;
+    if ((status = RtlFindMessage( module, RT_MESSAGETABLE, lang, id, &mre )) != STATUS_SUCCESS)
+    {
+        SetLastError( RtlNtStatusToDosError(status) );
+        return NULL;
+    }
 
     if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
     {
@@ -426,12 +436,7 @@ DWORD WINAPI FormatMessageA(
             from = load_messageA( (HMODULE)lpSource, dwMessageId, dwLanguageId );
         if (!from && (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM))
             from = load_messageA( kernel32_handle, dwMessageId, dwLanguageId );
-
-        if (!from)
-        {
-            SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
-            return 0;
-        }
+        if (!from) return 0;
     }
     target	= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
     t	= target;
@@ -597,12 +602,7 @@ DWORD WINAPI FormatMessageW(
             from = load_messageW( (HMODULE)lpSource, dwMessageId, dwLanguageId );
         if (!from && (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM))
             from = load_messageW( kernel32_handle, dwMessageId, dwLanguageId );
-
-        if (!from)
-        {
-            SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
-            return 0;
-        }
+        if (!from) return 0;
     }
     target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100 * sizeof(WCHAR) );
     t = target;
diff --git a/dlls/kernel32/tests/format_msg.c b/dlls/kernel32/tests/format_msg.c
index 2bbcfc8..15064b2 100644
--- a/dlls/kernel32/tests/format_msg.c
+++ b/dlls/kernel32/tests/format_msg.c
@@ -668,28 +668,28 @@ static void test_message_from_hmodule(void)
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
     error = GetLastError();
     ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
-    todo_wine ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
+    ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), out, sizeof(out)/sizeof(CHAR), NULL);
     error = GetLastError();
     ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
-    todo_wine ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
+    ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
                          MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT), out, sizeof(out)/sizeof(CHAR), NULL);
     error = GetLastError();
     ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
-    todo_wine ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
+    ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
                          MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), out, sizeof(out)/sizeof(CHAR), NULL);
     error = GetLastError();
     ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
-    todo_wine ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
+    ok(error == ERROR_MR_MID_NOT_FOUND, "last error %u\n", error);
 
     SetLastError(0xdeadbeef);
     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,




More information about the wine-cvs mailing list