Add LoadStringWEx to access string resource for a specifc locale.
Use that in mbox when formatting string for log.
int
mbox(HWND owner, unsigned int format_id, int mb_type, ...)
{
- std::wstring fmt = LoadStringW(format_id);
+ std::wstring fmt = LoadStringWEx(format_id, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
if (fmt.empty())
fmt = L"Internal error: format string resource not found";
std::wstring buf = vformat(fmt, args);
va_end(args);
- // write to log as UTF8
+ // write unlocalized to log as UTF8
Log (LOG_PLAIN) << "mbox " << ": " << wstring_to_string(buf) << endLog;
if (unattended_mode)
return unattended_result(mb_type);
+ fmt = LoadStringW(format_id);
+ if (fmt.empty())
+ fmt = L"Internal error: format string resource not found";
+
+ va_start(args, mb_type);
+ buf = vformat(fmt, args);
+ va_end(args);
+
bool retry_continue = (mb_type & MB_TYPEMASK) == MB_RETRYCONTINUE;
if (retry_continue) {
mb_type &= ~MB_TYPEMASK;
#endif
}
+const std::wstring
+LoadStringWEx(UINT uID, UINT langId)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ // Convert the string ID into a bundle number
+ LPCSTR bundle = MAKEINTRESOURCE(uID / 16 + 1);
+ HRSRC hRes = ::FindResourceEx(hInstance, RT_STRING, bundle, langId);
+ if (hRes)
+ {
+ HGLOBAL h = ::LoadResource(hInstance, hRes);
+ if (h)
+ {
+ HGLOBAL hGlob = ::LockResource(h);
+
+ // walk string bundle
+ wchar_t *buf = (wchar_t *)hGlob;
+ for (unsigned int i = 0; i < (uID & 15); i++)
+ {
+ buf += 1 + (UINT)*buf;
+ }
+
+ int len = *buf;
+ return std::wstring(buf + 1, len);
+ }
+ }
+ // N.B.: Due to the way string bundles are encoded, there's no difference
+ // between an absent string resource whose bundle is present, and a string
+ // resource containing the null string.
+ return L"";
+}
+
const std::wstring
LoadStringW(unsigned int uID)
{
}
const std::wstring LoadStringW(unsigned int uID);
+const std::wstring LoadStringWEx(UINT uID, UINT langId);
+
bool is_developer_mode(void);
#endif /* SETUP_WIN32_H */