我的目标是在程序中执行外部可执行文件.首先,我使用了system()函数,但我不希望向用户看到控制台.所以,我搜索了一下,找到了CreateProcess()功能.但是,当我尝试将参数传递给它时,我不知道为什么,它失败了.我从MSDN中获取了这段代码,并稍作改动:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void _tmain( int argc, TCHAR *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
/*
if( argc != 2 )
{
printf("Usage: %s [cmdline]\n", argv[0]);
return;
}
*/
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
L"c:\\users\\e\\desktop\\mspaint.exe", // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, …Run Code Online (Sandbox Code Playgroud)