Commit 100131d4 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Propagate the error result from RtlFindMessage in FormatMessage.

parent b381958f
......@@ -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;
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment