Commit 937d0b24 authored by Ryan Cumming's avatar Ryan Cumming Committed by Alexandre Julliard

Handle FORMAT_MESSAGE_FROM_HMODULE and FORMAT_MESSAGE_FROM_SYSTEM both

being set at once.
parent 4ce28377
...@@ -171,8 +171,6 @@ DWORD WINAPI FormatMessageA( ...@@ -171,8 +171,6 @@ DWORD WINAPI FormatMessageA(
TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n", TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n",
dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
&& (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
if ((dwFlags & FORMAT_MESSAGE_FROM_STRING) if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
&&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
|| (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0; || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
...@@ -186,29 +184,47 @@ DWORD WINAPI FormatMessageA( ...@@ -186,29 +184,47 @@ DWORD WINAPI FormatMessageA(
strcpy( from, (LPSTR)lpSource ); strcpy( from, (LPSTR)lpSource );
} }
else { else {
if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) bufsize = 0;
hmodule = GetModuleHandleA("kernel32");
bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)
if (!bufsize) { {
if (dwLanguageId) { bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100);
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); if ((!bufsize) && (!dwLanguageId)) {
return 0; bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100);
} }
bufsize=load_messageA(hmodule,dwMessageId, }
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100); if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) && (!bufsize))
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, {
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100); hmodule = GetModuleHandleA("kernel32");
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100);
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100); if ((!bufsize) && (!dwLanguageId)) {
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100); MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100); MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100);
if (!bufsize) { if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
return 0; if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100);
} }
} }
if (!bufsize) {
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
return 0;
}
from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 );
load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1); load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1);
} }
...@@ -406,8 +422,6 @@ DWORD WINAPI FormatMessageW( ...@@ -406,8 +422,6 @@ DWORD WINAPI FormatMessageW(
TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n", TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n",
dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
&& (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)) return 0;
if ((dwFlags & FORMAT_MESSAGE_FROM_STRING) if ((dwFlags & FORMAT_MESSAGE_FROM_STRING)
&&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM)
|| (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0; || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0;
...@@ -419,29 +433,47 @@ DWORD WINAPI FormatMessageW( ...@@ -419,29 +433,47 @@ DWORD WINAPI FormatMessageW(
from = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lpSource); from = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lpSource);
} }
else { else {
if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) bufsize = 0;
hmodule = GetModuleHandleA("kernel32");
bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE)
if (!bufsize) { {
if (dwLanguageId) { bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100);
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); if ((!bufsize) && (!dwLanguageId)) {
return 0; bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100);
} }
bufsize=load_messageA(hmodule,dwMessageId, }
MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100); if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) && (!bufsize))
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, {
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100); hmodule = GetModuleHandleA("kernel32");
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100);
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100); if ((!bufsize) && (!dwLanguageId)) {
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100); MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId, if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100); MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),NULL,100);
if (!bufsize) { if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
return 0; if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_NEUTRAL,SUBLANG_SYS_DEFAULT),NULL,100);
if (!bufsize) bufsize=load_messageA(hmodule,dwMessageId,
MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),NULL,100);
} }
} }
if (!bufsize) {
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
return 0;
}
from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 );
load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1); load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1);
} }
......
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