作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将一个字符串传递给我的 CreateProcess 函数,以便我可以将这个函数用于我的所有操作。如何正确地做到这一点?
下面是我的代码:
CString ExecuteExternalProgram(CString pictureName)
{
CString parameterOne = _T(" -format \"%h\" C:\\");
CString filename = pictureName;
CString parameterLast = _T("\"");
CString parameterFull = parameterOne + filename + parameterLast;
CreateProcess(_T("C:\\identify.exe"), parameterFull,0,0,TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);
CloseHandle(wPipe);
.......
}
最佳答案
您需要执行以下操作:
CreateProcess(L"C:\\identify.exe",csExecute.GetBuffer(),0,0,TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);
CreateProcess()
出于某种原因需要命令行参数的可写缓冲区,因此
CString
的隐式转换到一个普通的旧指针不会发生(因为如果它是一个 const 指针,它只会执行隐式转换)。
int main() {
CString csExecute = "some string data";
STARTUPINFO sInfo = {0};
sInfo.cb = sizeof(sInfo);
PROCESS_INFORMATION pInfo = {0};
CreateProcess(L"C:\\util\\echoargs.exe",csExecute.GetBuffer(),0,0,TRUE,
NORMAL_PRIORITY_CLASS,0,0,&sInfo,&pInfo);
return 0;
}
关于visual-c++ - 如何将字符串传递给 CreateProcess 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4589866/
我是一名优秀的程序员,十分优秀!