假设我希望程序"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;
}因为互联网上没有太多关于ShellExecuteEx变量参数的信息,所以我无法找到正确的解释。
你们中有人知道如何解决这个问题吗?提前感谢!
发布于 2015-03-17 09:53:23
仅仅是因为您的构造生成了一个临时对象,指向它的指针(我猜是一个CString )被存储了,但是在启动程序时,临时对象已经被销毁了。
auto str = _T("\"\"") _T(" ") + dir + file[i] + _T(" ") + dir + outputfile + _T(".TIFF");
ShExecInfo.lpParameters = str;
ShellExecuteEx(&ShExecInfo);发布于 2015-03-17 09:52:21
您是否检查了MyProgram接收到的这两个参数,它们有哪些值?
问题很可能是这段代码:
ShExecInfo.lpParameters = _T("\"\"") _T(" ") + dir + file[i] + _T(" ") + dir + outputfile + _T(".TIFF");您没有说明dir或file[i]有哪些类型,但通常添加这样的C样式字符串(TCHAR[]或TCHAR*仍然是C样式字符串)不会将它们连接在一起,如果这种情况是您期望的那样的话。
检查赋值后ShExecInfo.lpParameters包含的内容,方法是显示它,或者最好使用调试器。
https://stackoverflow.com/questions/29095329
复制相似问题