36 int len = MultiByteToWideChar(
37 codepage, 0,
String.c_str(), -1,
nullptr, 0);
39 wchar_t* buff =
static_cast<wchar_t*
>(
40 _alloca(len *
sizeof(
wchar_t)));
43 codepage, 0,
String.c_str(), -1, buff, len);
45 return std::wstring(buff);
50 int len = WideCharToMultiByte(
51 codepage, 0,
String.c_str(), -1,
nullptr, 0,
nullptr,
nullptr);
53 char* buff =
static_cast<char*
>(
54 _alloca(len *
sizeof(
char)));
57 codepage, 0,
String.c_str(), -1, buff, len,
nullptr,
nullptr);
59 return std::string(buff);
90 return std::wstring(szResStr);
102 if (
String.length() == 0 )
105 const wchar_t*
p =
String.c_str();
124 std::wstring shortName = aLongName;
125 DWORD
length = GetShortPathNameW( aLongName.c_str(),
nullptr, 0 );
129 auto buffer = std::make_unique<WCHAR[]>(
length+1 );
130 length = GetShortPathNameW( aLongName.c_str(), buffer.get(),
length );
132 shortName = std::wstring( buffer.get() );
157 return GetSystemDefaultLCID();
159 USHORT usPrimaryLang= LANG_NEUTRAL;
160 USHORT usSubLang=SUBLANG_DEFAULT;
162 ::std::wstring wsLanguage(
Locale.first);
163 ::std::wstring wsCountry(
Locale.second);
165 if ( wsLanguage == L
"ar" )
167 usPrimaryLang = LANG_ARABIC;
169 if ( wsCountry == L
"SA" )
170 usSubLang = SUBLANG_ARABIC_SAUDI_ARABIA;
171 else if ( wsCountry == L
"IQ" )
172 usSubLang = SUBLANG_ARABIC_IRAQ;
173 else if ( wsCountry == L
"EG" )
174 usSubLang = SUBLANG_ARABIC_EGYPT;
175 else if ( wsCountry == L
"LY" )
176 usSubLang = SUBLANG_ARABIC_LIBYA;
177 else if ( wsCountry == L
"DZ" )
178 usSubLang = SUBLANG_ARABIC_ALGERIA;
179 else if ( wsCountry == L
"MA" )
180 usSubLang = SUBLANG_ARABIC_MOROCCO;
181 else if ( wsCountry == L
"TN" )
182 usSubLang = SUBLANG_ARABIC_TUNISIA;
183 else if ( wsCountry == L
"OM" )
184 usSubLang = SUBLANG_ARABIC_OMAN;
185 else if ( wsCountry == L
"YE" )
186 usSubLang = SUBLANG_ARABIC_YEMEN;
187 else if ( wsCountry == L
"SY" )
188 usSubLang = SUBLANG_ARABIC_SYRIA;
189 else if ( wsCountry == L
"JO" )
190 usSubLang = SUBLANG_ARABIC_JORDAN;
191 else if ( wsCountry == L
"LB" )
192 usSubLang = SUBLANG_ARABIC_LEBANON;
193 else if ( wsCountry == L
"KW" )
194 usSubLang = SUBLANG_ARABIC_KUWAIT;
195 else if ( wsCountry == L
"AE" )
196 usSubLang = SUBLANG_ARABIC_UAE;
197 else if ( wsCountry == L
"BH" )
198 usSubLang = SUBLANG_ARABIC_BAHRAIN;
199 else if ( wsCountry == L
"QA" )
200 usSubLang = SUBLANG_ARABIC_QATAR;
202 usSubLang = SUBLANG_DEFAULT;
204 else if ( wsLanguage == L
"bg" )
205 usPrimaryLang = LANG_BULGARIAN;
206 else if ( wsLanguage == L
"ca" )
207 usPrimaryLang = LANG_CATALAN;
208 else if ( wsLanguage == L
"zh" )
210 usPrimaryLang = LANG_CHINESE;
211 if ( wsCountry == L
"TW" )
212 usSubLang = SUBLANG_CHINESE_TRADITIONAL;
213 else if ( wsCountry == L
"CN" )
214 usSubLang = SUBLANG_CHINESE_SIMPLIFIED;
215 else if ( wsCountry == L
"HK" )
216 usSubLang = SUBLANG_CHINESE_HONGKONG;
217 else if ( wsCountry == L
"SG" )
218 usSubLang = SUBLANG_CHINESE_SINGAPORE;
219 else if ( wsCountry == L
"MO" )
220 usSubLang = SUBLANG_CHINESE_MACAU;
222 usSubLang = SUBLANG_DEFAULT;
224 else if ( wsLanguage == L
"cs" )
225 usPrimaryLang = LANG_CZECH;
226 else if ( wsLanguage == L
"da" )
227 usPrimaryLang = LANG_DANISH;
228 else if ( wsLanguage == L
"de" )
230 usPrimaryLang = LANG_GERMAN;
231 if ( wsCountry == L
"DE" )
232 usSubLang = SUBLANG_GERMAN;
233 else if ( wsCountry == L
"CH" )
234 usSubLang = SUBLANG_GERMAN_SWISS;
235 else if ( wsCountry == L
"AT" )
236 usSubLang = SUBLANG_GERMAN_AUSTRIAN;
237 else if ( wsCountry == L
"LU" )
238 usSubLang = SUBLANG_GERMAN_LUXEMBOURG;
239 else if ( wsCountry == L
"LI" )
240 usSubLang = SUBLANG_GERMAN_LIECHTENSTEIN;
242 usSubLang = SUBLANG_DEFAULT;
244 else if ( wsLanguage == L
"el" )
245 usPrimaryLang = LANG_GREEK;
246 else if ( wsLanguage == L
"en" )
248 usPrimaryLang = LANG_ENGLISH;
249 if ( wsCountry == L
"US" )
250 usSubLang = SUBLANG_ENGLISH_US;
251 else if ( wsCountry == L
"GB" )
252 usSubLang = SUBLANG_ENGLISH_UK;
253 else if ( wsCountry == L
"AU" )
254 usSubLang = SUBLANG_ENGLISH_AUS;
255 else if ( wsCountry == L
"CA" )
256 usSubLang = SUBLANG_ENGLISH_CAN;
257 else if ( wsCountry == L
"NZ" )
258 usSubLang = SUBLANG_ENGLISH_NZ;
259 else if ( wsCountry == L
"IE" )
260 usSubLang = SUBLANG_ENGLISH_EIRE;
261 else if ( wsCountry == L
"ZA" )
262 usSubLang = SUBLANG_ENGLISH_SOUTH_AFRICA;
263 else if ( wsCountry == L
"JM" )
264 usSubLang = SUBLANG_ENGLISH_JAMAICA;
265 else if ( wsCountry == L
"GD" )
266 usSubLang = SUBLANG_ENGLISH_CARIBBEAN;
267 else if ( wsCountry == L
"BZ" )
268 usSubLang = SUBLANG_ENGLISH_BELIZE;
269 else if ( wsCountry == L
"TT" )
270 usSubLang = SUBLANG_ENGLISH_TRINIDAD;
271 else if ( wsCountry == L
"ZW" )
272 usSubLang = SUBLANG_ENGLISH_ZIMBABWE;
273 else if ( wsCountry == L
"PH" )
274 usSubLang = SUBLANG_ENGLISH_PHILIPPINES;
276 usSubLang = SUBLANG_DEFAULT;
278 else if ( wsLanguage == L
"es" )
281 if ( wsCountry == L
"MX" )
282 usSubLang = SUBLANG_SPANISH_MEXICAN;
283 else if ( wsCountry == L
"ES" )
284 usSubLang = SUBLANG_SPANISH_MODERN;
285 else if ( wsCountry == L
"GT" )
286 usSubLang = SUBLANG_SPANISH_GUATEMALA;
287 else if ( wsCountry == L
"CR" )
288 usSubLang = SUBLANG_SPANISH_COSTA_RICA;
289 else if ( wsCountry == L
"PA" )
290 usSubLang = SUBLANG_SPANISH_PANAMA;
291 else if ( wsCountry == L
"DO" )
292 usSubLang = SUBLANG_SPANISH_DOMINICAN_REPUBLIC;
293 else if ( wsCountry == L
"VE" )
294 usSubLang = SUBLANG_SPANISH_VENEZUELA;
295 else if ( wsCountry == L
"CO" )
296 usSubLang = SUBLANG_SPANISH_COLOMBIA;
297 else if ( wsCountry == L
"PE" )
298 usSubLang = SUBLANG_SPANISH_PERU;
299 else if ( wsCountry == L
"AR" )
300 usSubLang = SUBLANG_SPANISH_ARGENTINA;
301 else if ( wsCountry == L
"EC" )
302 usSubLang = SUBLANG_SPANISH_ECUADOR;
303 else if ( wsCountry == L
"CL" )
304 usSubLang = SUBLANG_SPANISH_CHILE;
305 else if ( wsCountry == L
"UY" )
306 usSubLang = SUBLANG_SPANISH_URUGUAY;
307 else if ( wsCountry == L
"PY" )
308 usSubLang = SUBLANG_SPANISH_PARAGUAY;
309 else if ( wsCountry == L
"BO" )
310 usSubLang = SUBLANG_SPANISH_BOLIVIA;
311 else if ( wsCountry == L
"SV" )
312 usSubLang = SUBLANG_SPANISH_EL_SALVADOR;
313 else if ( wsCountry == L
"HN" )
314 usSubLang = SUBLANG_SPANISH_HONDURAS;
315 else if ( wsCountry == L
"NI" )
316 usSubLang = SUBLANG_SPANISH_NICARAGUA;
317 else if ( wsCountry == L
"PR" )
318 usSubLang = SUBLANG_SPANISH_PUERTO_RICO;
320 usSubLang = SUBLANG_DEFAULT;
322 else if ( wsLanguage == L
"fi" )
323 usPrimaryLang = LANG_FINNISH;
324 else if ( wsLanguage == L
"fr" )
326 usPrimaryLang = LANG_FRENCH;
327 if ( wsCountry == L
"FR" )
328 usSubLang = SUBLANG_FRENCH;
329 else if ( wsCountry == L
"BE" )
330 usSubLang = SUBLANG_FRENCH_BELGIAN;
331 else if ( wsCountry == L
"CA" )
332 usSubLang = SUBLANG_FRENCH_CANADIAN;
333 else if ( wsCountry == L
"CH" )
334 usSubLang = SUBLANG_FRENCH_SWISS;
335 else if ( wsCountry == L
"LU" )
336 usSubLang = SUBLANG_FRENCH_LUXEMBOURG;
337 else if ( wsCountry == L
"MC" )
338 usSubLang = SUBLANG_FRENCH_MONACO;
340 usSubLang = SUBLANG_DEFAULT;
342 else if ( wsLanguage == L
"iw" )
343 usPrimaryLang = LANG_HEBREW;
344 else if ( wsLanguage == L
"hu" )
345 usPrimaryLang = LANG_HUNGARIAN;
346 else if ( wsLanguage == L
"is" )
347 usPrimaryLang = LANG_ICELANDIC;
348 else if ( wsLanguage == L
"it" )
350 usPrimaryLang = LANG_ITALIAN;
351 if ( wsCountry == L
"IT" )
352 usSubLang = SUBLANG_ITALIAN;
353 else if ( wsCountry == L
"CH" )
354 usSubLang = SUBLANG_ITALIAN_SWISS;
356 usSubLang = SUBLANG_DEFAULT;
358 else if ( wsLanguage == L
"ja" )
359 usPrimaryLang = LANG_JAPANESE;
360 else if ( wsLanguage == L
"ko" )
362 usPrimaryLang = LANG_KOREAN;
363 if ( wsCountry == L
"KR" )
364 usSubLang = SUBLANG_KOREAN;
366 usSubLang = SUBLANG_DEFAULT;
368 else if ( wsLanguage == L
"nl" )
370 usPrimaryLang = LANG_DUTCH;
371 if ( wsCountry == L
"NL" )
372 usSubLang = SUBLANG_DUTCH;
373 else if ( wsCountry == L
"BE" )
374 usSubLang = SUBLANG_DUTCH_BELGIAN;
376 usSubLang = SUBLANG_DEFAULT;
378 else if ( wsLanguage == L
"no" )
380 usPrimaryLang = LANG_NORWEGIAN;
381 if ( wsCountry == L
"NO" )
382 usSubLang = SUBLANG_NORWEGIAN_BOKMAL;
384 usSubLang = SUBLANG_DEFAULT;
386 else if ( wsLanguage == L
"pl" )
387 usPrimaryLang = LANG_POLISH;
388 else if ( wsLanguage == L
"pt" )
390 usPrimaryLang = LANG_PORTUGUESE;
391 if ( wsCountry == L
"BR" )
392 usSubLang = SUBLANG_PORTUGUESE_BRAZILIAN;
393 else if ( wsCountry == L
"PT" )
394 usSubLang = SUBLANG_PORTUGUESE;
396 usSubLang = SUBLANG_DEFAULT;
398 else if ( wsLanguage == L
"ro" )
399 usPrimaryLang = LANG_ROMANIAN;
400 else if ( wsLanguage == L
"ru" )
401 usPrimaryLang = LANG_RUSSIAN;
402 else if ( wsLanguage == L
"hr" )
403 usPrimaryLang = LANG_CROATIAN;
404 else if ( wsLanguage == L
"sr" )
406 usPrimaryLang = LANG_SERBIAN;
407 if ( wsCountry == L
"VA" )
408 usSubLang = SUBLANG_SERBIAN_LATIN;
409 else if ( wsCountry == L
"HR" )
410 usSubLang = SUBLANG_SERBIAN_CYRILLIC;
412 usSubLang = SUBLANG_DEFAULT;
414 else if ( wsLanguage == L
"sk" )
415 usPrimaryLang = LANG_SLOVAK;
416 else if ( wsLanguage == L
"sq" )
417 usPrimaryLang = LANG_ALBANIAN;
418 else if ( wsLanguage == L
"sv" )
420 usPrimaryLang = LANG_SWEDISH;
421 if ( wsCountry == L
"SE" )
422 usSubLang = SUBLANG_SWEDISH;
423 else if ( wsCountry == L
"FI" )
424 usSubLang = SUBLANG_SWEDISH_FINLAND;
426 usSubLang = SUBLANG_DEFAULT;
428 else if ( wsLanguage == L
"th" )
429 usPrimaryLang = LANG_THAI;
430 else if ( wsLanguage == L
"tr" )
431 usPrimaryLang = LANG_TURKISH;
432 else if ( wsLanguage == L
"ur" )
434 usPrimaryLang = LANG_URDU;
435 if ( wsCountry == L
"PK" )
436 usSubLang = SUBLANG_URDU_PAKISTAN;
437 else if ( wsCountry == L
"IN" )
438 usSubLang = SUBLANG_URDU_INDIA;
440 usSubLang = SUBLANG_DEFAULT;
442 else if ( wsLanguage == L
"in" )
443 usPrimaryLang = LANG_INDONESIAN;
444 else if ( wsLanguage == L
"uk" )
445 usPrimaryLang = LANG_UKRAINIAN;
446 else if ( wsLanguage == L
"be" )
447 usPrimaryLang = LANG_BELARUSIAN;
448 else if ( wsLanguage == L
"sl" )
449 usPrimaryLang = LANG_SLOVENIAN;
450 else if ( wsLanguage == L
"et" )
451 usPrimaryLang = LANG_ESTONIAN;
452 else if ( wsLanguage == L
"lv" )
453 usPrimaryLang = LANG_LATVIAN;
454 else if ( wsLanguage == L
"lt" )
456 usPrimaryLang = LANG_LITHUANIAN;
457 if ( wsCountry == L
"LT" )
458 usSubLang = SUBLANG_LITHUANIAN;
460 usSubLang = SUBLANG_DEFAULT;
462 else if ( wsLanguage == L
"fa" )
463 usPrimaryLang = LANG_FARSI;
464 else if ( wsLanguage == L
"vi" )
465 usPrimaryLang = LANG_VIETNAMESE;
466 else if ( wsLanguage == L
"hy" )
467 usPrimaryLang = LANG_ARMENIAN;
468 else if ( wsLanguage == L
"az" )
469 usPrimaryLang = LANG_AZERI;
470 else if ( wsLanguage == L
"eu" )
471 usPrimaryLang = LANG_BASQUE;
472 else if ( wsLanguage == L
"mk" )
473 usPrimaryLang = LANG_MACEDONIAN;
474 else if ( wsLanguage == L
"af" )
475 usPrimaryLang = LANG_AFRIKAANS;
476 else if ( wsLanguage == L
"ka" )
477 usPrimaryLang = LANG_GEORGIAN;
478 else if ( wsLanguage == L
"fo" )
479 usPrimaryLang = LANG_FAEROESE;
480 else if ( wsLanguage == L
"hi" )
481 usPrimaryLang = LANG_HINDI;
482 else if ( wsLanguage == L
"ms" )
484 usPrimaryLang = LANG_MALAY;
485 if ( wsCountry == L
"MY" )
486 usSubLang = SUBLANG_MALAY_MALAYSIA;
487 else if ( wsCountry == L
"BN" )
488 usSubLang = SUBLANG_MALAY_BRUNEI_DARUSSALAM;
490 usSubLang = SUBLANG_DEFAULT;
492 else if ( wsLanguage == L
"kk" )
493 usPrimaryLang = LANG_KAZAK;
494 else if ( wsLanguage == L
"ky" )
495 usPrimaryLang = LANG_KYRGYZ;
496 else if ( wsLanguage == L
"sw" )
497 usPrimaryLang = LANG_SWAHILI;
498 else if ( wsLanguage == L
"uz" )
500 usPrimaryLang = LANG_UZBEK;
501 if ( wsCountry == L
"UZ" )
502 usSubLang = SUBLANG_UZBEK_LATIN;
503 else if ( wsCountry == L
"DE" )
504 usSubLang = SUBLANG_UZBEK_CYRILLIC;
506 usSubLang = SUBLANG_DEFAULT;
508 else if ( wsLanguage == L
"tt" )
509 usPrimaryLang = LANG_TATAR;
510 else if ( wsLanguage == L
"bn" )
511 usPrimaryLang = LANG_BENGALI;
512 else if ( wsLanguage == L
"pa" )
513 usPrimaryLang = LANG_PUNJABI;
514 else if ( wsLanguage == L
"gu" )
515 usPrimaryLang = LANG_GUJARATI;
516 else if ( wsLanguage == L
"or" )
517 usPrimaryLang = LANG_ORIYA;
518 else if ( wsLanguage == L
"ta" )
519 usPrimaryLang = LANG_TAMIL;
520 else if ( wsLanguage == L
"te" )
521 usPrimaryLang = LANG_TELUGU;
522 else if ( wsLanguage == L
"kn" )
523 usPrimaryLang = LANG_KANNADA;
524 else if ( wsLanguage == L
"ml" )
525 usPrimaryLang = LANG_MALAYALAM;
526 else if ( wsLanguage == L
"as" )
527 usPrimaryLang = LANG_ASSAMESE;
528 else if ( wsLanguage == L
"mr" )
529 usPrimaryLang = LANG_MARATHI;
530 else if ( wsLanguage == L
"sa" )
531 usPrimaryLang = LANG_SANSKRIT;
532 else if ( wsLanguage == L
"mn" )
533 usPrimaryLang = LANG_MONGOLIAN;
534 else if ( wsLanguage == L
"gl" )
535 usPrimaryLang = LANG_GALICIAN;
536 else if ( wsLanguage == L
"sd" )
537 usPrimaryLang = LANG_SINDHI;
538 else if ( wsLanguage == L
"ks" )
539 usPrimaryLang = LANG_KASHMIRI;
540 else if ( wsLanguage == L
"ne" )
541 usPrimaryLang = LANG_NEPALI;
543 return GetSystemDefaultLCID();
545 return MAKELCID( MAKELANGID( usPrimaryLang, usSubLang ), SORT_DEFAULT );
553 if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
554 | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
558 const DWORD dwError = GetLastError();
560 L
"GetCurrentModuleHandle: GetModuleHandleExW failed, error is 0x%X", dwError);
const LocaleSet_t EMPTY_LOCALE
::std::pair< Language_t, Country_t > LocaleSet_t
std::wstring GetResString(int ResId)
Retrieve a string from the resources of this module.
bool HasOnlySpaces(const std::wstring &String)
helper function to judge if the string is only has spaces.
const size_t MAX_RES_STRING
static std::string WStringToString(const std::wstring &String, int codepage)
std::wstring UTF8ToWString(const std::string &String)
Convert a string to a wstring using CP_UTF8.
LCID LocaleSetToLCID(const LocaleSet_t &Locale)
convert LocaleSet pair into Microsoft List of Locale ID (LCID) according to ISO-639 and ISO-3166.
HMODULE GetCurrentModuleHandle()
std::wstring getShortPathName(const std::wstring &aLongName)
helper function to convert windows paths to short form.
static std::wstring StringToWString(const std::string &String, int codepage)
void OutputDebugStringFormatW(LPCWSTR pFormat,...)