3

現在、パス、引数、および環境変数でCreateProcessを使用しようとしています。私の変数は文字列に格納されています。

以下の例では、filePath と cmdArgs は正常に動作しますが、envVars を動作させることができません。

std::string filePath = "C:\\test\\DummyApp.exe";
std::string cmdArgs  = "Arg1 Arg2 Arg3";
std::string envVars  = "first=test\0second=jam\0";  // One

//LPTSTR testStr = "first=test\0second=jam\0";      // Two

CreateProcess(
   LPTSTR(filePath.c_str()),           //path and application name
   LPTSTR(cmdArgs.c_str()),            // Command line
   NULL,                               // Process handle not inheritable
   NULL,                               // Thread handle not inheritable
   TRUE,                               // Set handle inheritance
   0,                                  // Creation flags
   LPTSTR(envVars.c_str()),            // environment block
   //testStr                      //this line works
   NULL,                               // Use parent's starting directory 
   &si,                                // Pointer to STARTUPINFO structure
   &pi )                               // Pointer to PROCESS_INFORMATION structure

)

このコードを実行すると、「エラー 87: パラメータが正しくありません」というエラーが返されます。

私が理解していないのは、「1」というラベルの付いた行をコメントアウトし、「2」というラベルの付いた行に置き換える (関数呼び出しで一致するスワップを作成する) と、正しく動作するということです。

4

1 に答える 1