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 不传递命令行参数
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01