.iniファイルから読み取ったパス文字列を関数で動作させるために2時間費やしてきましたが、これは。CreateProcessを期待していLPCWSTRます。どういうわけか、どうしても動かない。
次のコードがあります。これは別のSOの回答から取得し、使用するために修正しましたが、CreateProcessそれでもプロセスが開始されません。
誰か助けてもらえますか?
std::ifstream file(file_path.c_str());
settings new_settings;
if(file.is_open() && !file.fail())
{
std::string key;
char sign = '=';
std::string value;
std::string line;
while(!file.eof())
{
std::getline(file, key, sign);
std::getline(file, value);
//fill in settings struct with `value` variable. Struct contains only `std::string` types.
}
}
file.close();
PROCESS_INFORMATION proc_info;
STARTUPINFO start_info;
memset(&start_info, 0, sizeof(start_info));
start_info->cb = sizeof(STARTUPINFO);
std::string path = "C:\\Mydir\\myexe.exe";
int len;
int slength = (int)path.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, buf, len);
std::wstring wpath(buf);
delete[] buf;
LPCWSTR p_path = wpath.c_str();
created = CreateProcess(p_path, lpPort, 0,0, FALSE, CREATE_NEW_CONSOLE,NULL,NULL,&start_info ,&proc_info);
DWORD dwErr = GetLastError(); //Returns 0x7b (Invalid Path Or FileName)