Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
LocalRun: Run application in specified locale (chs as hard-coded).
* Local(e)Run: Run application in specified locale (chs as hard-coded).
* Originial purpose: run fterm.exe in non-Chinese(PRC) locale.
* Author:
#include <stdio.h>
#include <tchar.h>
#include <locale.h>
#include <process.h>
#include <windows.h>
#include <mbctype.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
int _tmain(int argc, _TCHAR* argv[])
// Please refer to
L"The process locale is now set to %s.\n",
_wsetlocale(LC_ALL, L"chs"));
int ret = _setmbcp(_MB_CP_LOCALE);
switch (ret)
case -1:
MessageBox(NULL, L"Invalid code page value is supplied for codepage.", L"Error", MB_ICONERROR);
return 1;
case 0:
MessageBox(NULL, L"Error while setting locale for MBCS app.", L"Error", MB_ICONERROR);
return 1;
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;
memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
if (argc != 2)
MessageBox(NULL, L"No application path specified.", L"File path parameter required", MB_ICONERROR);
return 2;
if (!PathFileExists(argv[1]))
MessageBox(NULL, argv[1], L"File not found", MB_ICONERROR);
return 3;
BOOL pros = CreateProcess(NULL, argv[1], NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
if (!pros)
MessageBox(NULL, argv[1], L"Failed to create process with required locale", MB_ICONERROR);
return 4;
CloseHandle( processInformation.hProcess );
CloseHandle( processInformation.hThread );
return 0;
Copy link

ghost commented Mar 8, 2021

setlocale(LC_ALL, "ja-JP");
我按这个测试api都成功了,但是子进程就没有效果; 你这个有测试成功的数据吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment