CreateProcess doesn#39;t pass command line arguments(CreateProcess 不传递命令行参数)
问题描述
您好,我有以下代码,但没有按预期工作,无法弄清楚问题出在哪里.
Hello I have the following code but it isn't working as expected, can't figure out what the problem is.
基本上,我正在执行一个进程(一个 .NET 进程)并传递命令行参数,它由 CreateProcess() 成功执行,但 CreateProcess() 没有传递命令行参数
Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments
我在这里做错了什么??
What am I doing wrong here??
int main(int argc, char* argv[])
{
PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
LPTSTR cmdArgs = "name@example.com";
if(CreateProcess("D:\email\smtp.exe", cmdArgs,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
printf("Yohoo!");
}
else
{
printf("The process could not be started...");
}
return 0;
}
嘿还有一件事,如果我像这样传递我的 cmdArgs
:
Hey one more thing, if I pass my cmdArgs
like this:
// a space as the first character
LPTSTR cmdArgs = " name@example.com";
然后我得到错误,然后 CreateProcess 返回 TRUE
但我的目标进程没有执行.
Then I get the error, then CreateProcess returns TRUE
but my target process isn't executed.
Object reference not set to an instance of an object
推荐答案
你应该在参数中指定还模块名称:LPTSTR cmdArgs = "App name@example.com";代码>它应该是整个命令行(包括 argv[0]).
You should specify also the module name in parameters: LPTSTR cmdArgs = "App name@example.com";
It should be the whole command line (including argv[0]).
这篇关于CreateProcess 不传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CreateProcess 不传递命令行参数


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01