ifstream::open と CreateProcess の両方で文字列を使用する必要があるコードがあります。
//in another file
const char* FILENAME = "C:\\...blah blah\\filename.bat";
// in main app
std::ifstream is;
is.open(FILENAME);
// ...do some writing
is.close();
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
std::string cmdLine = "/c " + FILENAME;
if( !CreateProcess( "c:\\Windows\\system32\\cmd.exe",
cmdLine.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi) )
{
return GetLastError();
}
CreateProcess には LPCWSTR が必要なので、CreateProcess で文字列を使用するには、ファイル名と「cmdLine」を std::wstring として宣言する必要がありますが、ifstream::open はワイド文字列を取りません...方法がわかりませんこれを回避するために。私は常に、ユニコードとマルチバイト文字列の問題に遭遇しているようです。
何か案は?ありがとう。