#include #include #include #define TRACE printf static INT NLS_LoadStringExW(HRSRC hrsrc, LANGID lang_id, UINT res_id, LPWSTR buffer, INT buflen) { HGLOBAL hmem; WCHAR *p; int string_num; int i; if(!hrsrc) { printf("hrsrc = 0\n"); return 0; } hmem = LoadResource(NULL, hrsrc); if(!hmem) { printf("LoadResource returned 0\n"); return 0; } p = LockResource(hmem); string_num = res_id & 0x000f; for(i = 0; i < string_num; i++) p += *p + 1; // TRACE("strlen = %d\n", (int)*p ); if (buffer == NULL) return *p; i = min(buflen - 1, *p); if (i > 0) { memcpy(buffer, p + 1, i * sizeof (WCHAR)); buffer[i] = (WCHAR) 0; } else { if (buflen > 1) buffer[0] = (WCHAR) 0; } FreeResource(hmem); TRACE("\"%ws\"\n", buffer); return (i + 1); } void FindResource_test(LANGID lang_id) { HMODULE hModule = GetModuleHandleW(NULL); HRSRC hrsrc; WCHAR wcBuffer[128]; CHAR acBuffer[128]; printf("Testing LoadStringA: "); if(LoadStringA(hModule, 1, acBuffer, 128)) printf("\"%s\"\n", acBuffer); else printf("LoadStringA returned 0\n"); printf("Testing FindResourceA: "); hrsrc = FindResourceA(hModule, (LPCSTR)1, (LPCSTR)RT_STRING); if(!hrsrc) printf("FindResourceA returned 0\n"); else NLS_LoadStringExW(hrsrc, lang_id, 1, wcBuffer, 128); printf("Testing FindResourceExA(%04X; %02X %02X): ", lang_id, PRIMARYLANGID(lang_id), SUBLANGID(lang_id)); hrsrc = FindResourceExA(hModule, (LPCSTR)RT_STRING, (LPCSTR)1, lang_id); if(!hrsrc) printf("FindResourceExA returned 0\n"); else NLS_LoadStringExW(hrsrc, lang_id, 1, wcBuffer, 128); } static BOOL CALLBACK EnumResourceLanguagesProcW(HMODULE hModule, LPCWSTR type, LPCWSTR name, WORD LangID, LONG lParam) { printf("%08X\n", (UINT)LangID); return TRUE; } int main(int argc, char *argv[]) { LANGID lang_id; if(argc > 1) lang_id = (LANGID)strtol(argv[1], NULL, 0); else lang_id = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT); SetThreadLocale(MAKELCID(lang_id, SORT_DEFAULT)); printf("Thread locale = %04X\n", GetThreadLocale()); EnumResourceLanguagesW(GetModuleHandleA(NULL), (LPCWSTR)RT_STRING, (LPCWSTR)LOCALE_ILANGUAGE, EnumResourceLanguagesProcW, 0); FindResource_test(lang_id); return 0; } #if 0 Win95OS2PE LoadStringA/W and FindResourceA/W do search in the following order: 1. Neutral language with neutral sublanguage 2. Neutral language with default sublanguage 3. LANG_ENGLISH, SUBLANG_DEFAULT 4. Current locale lang id 5. Current locale lang id with neutral sublanguage 6. Return first in the list Win2000: LoadStringA/W and FindResourceA/W do search in the following order: 1. Neutral language with neutral sublanguage 2. LANG_ENGLISH, SUBLANG_DEFAULT 3. LANG_ENGLISH, SUBLANG_NEUTRAL 4. Current locale lang id 5. Current locale lang id with neutral sublanguage 6. Return first in the list FindResourceExA/W does search in the following order: 1. Exact specified language 2. Language with neutral sublanguage 3. Neutral language with neutral sublanguage 4. Neutral language with default sublanguage #endif