MFC CreateProcess不会将UTF8命令行arg传递给进程

时间:2012-02-02 11:43:31

标签: utf-8 mfc console-application

我尝试使用CreateProcess从MFC应用程序启动控制台应用程序 cmd 变量是CString,它包含应用程序名称和命令行arg,它是chineese UTF8文件名。
文件名不以UTF8格式传递,应用程序失败 如何以正确的方式发送命令?

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.
        );

3 个答案:

答案 0 :(得分:2)

根据您的编译器设置,您将调用当前代码页中带有CreateProcessA个字符串的char或带有Unicode UTF中CreateProcessW个字符串的wchar_t -16。这些都不能作为输入处理UTF-8字符串。

您应该将UTF-8字符串转换为UTF-16,然后从中构建命令行。

答案 1 :(得分:1)

假设您正在以多字节模式(而不是unicode)进行编译。

CT2W path(m_strProg);
CreateProcessW(path, ...);

答案 2 :(得分:-1)

只是说你有两个否定词,用英语表示它是积极的 - 所以你说它确实通过了UTF8。无论如何,您需要阅读http://www.joelonsoftware.com/articles/Unicode.html此外,您还需要更改您的语言区域和代码页,这与Unicode characters in Windows command line - how?

一致
相关问题