Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My OS is Windows XP English, in the console of my computer, I can not input Chinese. If i copy Chinese character into console, it will be converted to be question mark.

Therefore, if i run "javaw.exe [parameters with Chinese]" (e.g. "javew.exe Test中文.doc"), i will get "Test??.doc" in my java main().

Now, i'm using ShellExecuteEx() to execute a command in my project. The parameter passed into ShellExecuteEx() may contain unicode characters.



SHELLEXECUTEINFO shellExecuteInfo = {0};
shellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shellExecuteInfo.hwnd = NULL;
shellExecuteInfo.lpVerb = _T("open");
shellExecuteInfo.lpFile = "javaw.exe";
shellExecuteInfo.lpParameters = (wchar_t*)pParamUTF16Str; //pParamUTF16Str includes string "Test中文.doc";
shellExecuteInfo.lpDirectory = NULL;
shellExecuteInfo.nShow = SW_HIDE;
shellExecuteInfo.hInstApp = NULL;
bool ret = ShellExecuteEx(&shellExecuteInfo);



I also will get “Test??.doc” in my java main(), so i guess using ShellExecuteEx() is as same as running the command in Windows console (C:\Windows\system32\cmd.exe), is that right?

BTW, if i change the Language for non-Unicode programs to be "Chinese" in the regional and language options, then i can input Chinese in console and this code works well.

Thanks,

Aidy
Posted
Comments
Ryan Zahra 7-Mar-11 4:27am    
Some questions:
Is pParamUTF16Str a wide string?
Are you compiling your code in UNICODE?
Can you debug your code and check the value stored in shellExecuteInfo.lpParameters?
Are you sure that javaw.exe accepts UNICODE characters?
szh121 7-Mar-11 5:31am    
pParamUTF16Str is a UTF16 string, i'm not compiling my code in UNICODE. The parameter is user-inputted, not hard-code.
I can see shellExecuteInfo.lpParameters is correct when debugging.
I think javaw.exe can accept UNICODE characters, at least when my local setting is Chinese.

1 solution

In principle, you can input and output Chinese (anything using Unicode) in console application. I tried it. Console API has options to set up some Unicode UTF encodings. I did not do it with C++, but I did with .NET and, with native code, too, as much as I remember (Delphi), so after some search you can find where to set it up. Here is one source of information: Unicode Output to the Windows Console[^].

Starting "CMD.exe" is a problem. "CMD /U" allows to output Unicode but not input.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900