1

I try to start console application from MFC application using CreateProcess.
cmd variable is CString which contains the application name and command line arg which is chineese UTF8 file name.
The file name is not passed in UTF8 format and the application fails.
How can I send the command in the right way?

BOOL bRetVal = ::CreateProcess( NULL,             
        cmd.GetBuffer(m_strProg.GetLength()),                 // Command line. 
        NULL,             // Process handle not inheritable. 
        NULL,             // Thread handle not inheritable. 
        FALSE,            // Set handle inheritance to FALSE. 
        0,                // No creation flags. 
        NULL,             // Use parent's environment block. 
        NULL,             // Use parent's starting directory. 
        &si,              // Pointer to STARTUPINFO structure.
        &pi               // Pointer to PROCESS_INFORMATION structure.
        );
Costa Mirkin
  • 947
  • 3
  • 15
  • 39

3 Answers3

2

Depending on your compiler settings, you will be calling either CreateProcessA which takes char strings in the current code page, or CreateProcessW which takes wchar_t strings in Unicode UTF-16. Neither of those will be able to handle a UTF-8 string as input.

You should convert the UTF-8 string to UTF-16, then build your command line from that.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
1

Assuming you are compiling in multi-byte mode (not unicode).

CT2W path(m_strProg);
CreateProcessW(path, ...);
l33t
  • 18,692
  • 16
  • 103
  • 180
-1

Was just saying that you have two negatives there, in english that makes it a positive - so you were saying that it does, in fact, pass UTF8. Anyway, you need to read http://www.joelonsoftware.com/articles/Unicode.html Also, you need to change your locale and codepage, something along the lines of Unicode characters in Windows command line - how?

Community
  • 1
  • 1
Arafangion
  • 11,517
  • 1
  • 40
  • 72