Hi, FormatMessage currently fails if both the FORMAT_MESSAGE_FROM_HMODULE and FORMAT_MESSAGE_FROM_SYSTEM flags are set. However, MSDN states that in this case, the module's messages should be searched first, and then we should fall back on the system messages. This patch attempts to fix this. With this patch applied, WinXP's CMD.EXE can find its messages and becomes a lot more useful. ChangeLog: * dlls/kernel/format_msg.c Handle FORMAT_MESSAGE_FROM_HMODULE and FORMAT_MESSAGE_FROM_SYSTEM both being set at once -Ryan
Index: format_msg.c =================================================================== RCS file: /home/wine/wine/dlls/kernel/format_msg.c,v retrieving revision 1.24 diff -u -r1.24 format_msg.c --- format_msg.c 20 Aug 2002 00:32:48 -0000 1.24 +++ format_msg.c 4 Nov 2002 01:25:35 -0000 @@ -171,8 +171,6 @@ TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n", 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) &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0; @@ -186,29 +184,47 @@ strcpy( from, (LPSTR)lpSource ); } else { - if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) - hmodule = GetModuleHandleA("kernel32"); - bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); - if (!bufsize) { - if (dwLanguageId) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); - return 0; + bufsize = 0; + + if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) + { + bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); + if ((!bufsize) && (!dwLanguageId)) { + 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 (!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); - if (!bufsize) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); - return 0; + } + if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) && (!bufsize)) + { + hmodule = GetModuleHandleA("kernel32"); + bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); + if ((!bufsize) && (!dwLanguageId)) { + 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); } } + + if (!bufsize) { + SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); + return 0; + } + from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1); } @@ -406,8 +422,6 @@ TRACE("(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n", 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) &&((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) || (dwFlags & FORMAT_MESSAGE_FROM_HMODULE))) return 0; @@ -419,29 +433,47 @@ from = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lpSource); } else { - if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) - hmodule = GetModuleHandleA("kernel32"); - bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); - if (!bufsize) { - if (dwLanguageId) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); - return 0; + bufsize = 0; + + if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) + { + bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); + if ((!bufsize) && (!dwLanguageId)) { + 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 (!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); - if (!bufsize) { - SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); - return 0; + } + if ((dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) && (!bufsize)) + { + hmodule = GetModuleHandleA("kernel32"); + bufsize=load_messageA(hmodule,dwMessageId,dwLanguageId,NULL,100); + if ((!bufsize) && (!dwLanguageId)) { + 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); } } + + if (!bufsize) { + SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND); + return 0; + } + from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); load_messageA(hmodule,dwMessageId,dwLanguageId,from,bufsize+1); }