假设我希望程序“C:\ MyProgram.exe”以两个变量的参数运行。发生的问题是MyProgram仅接收2个参数,而我显然传递了3个参数。
我的代码:
SHELLEXECUTEINFO ShExecInfo = { 0 };
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShExecInfo.lpFile = T("\"C:\\MyProgram.exe\"");
ShExecInfo.lpParameters = _T("\"\"") _T(" ") + dir + file[i] + _T(" ") + dir + outputfile + _T(".TIFF");
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess, 1500);
if(GetExitCodeProcess(ShExecInfo.hProcess, &exitCode)){
MessageBox(_T("Conversion ") + file[i] + _T(" unsuccesful."), _T("TEST!"), MB_OK);
succes = 0;
}
因为Internet上关于ShellExecuteEx的可变参数的信息不多,所以我找不到合适的解释。
你们当中有人知道如何解决这个问题吗?
提前致谢!
最佳答案
仅仅是因为您的构造会变成一个临时对象,并且存储了指向它的指针(我猜是CString),但是启动程序时临时对象已经被破坏了。
auto str = _T("\"\"") _T(" ") + dir + file[i] + _T(" ") + dir + outputfile + _T(".TIFF");
ShExecInfo.lpParameters = str;
ShellExecuteEx(&ShExecInfo);