CreateProcess()编译错误
CreateProcess() compiling error?
我正试图弄清楚如何使用CreateProcess()函数,但我对C++并不太精通。我已经尝试了一些方法来消除错误,但应用程序似乎没有完成我期望它完成的操作。
我想做的是将"cmd.exe/c ipconfig>c:\test.txt"传递给它,并让它按预期执行。
我得到的错误(在开发C++中)是:
6 C:\Dev Cpp\project\test\Unttled1.Cpp
main' must return
int'
C: \Dev Cpp\project\test\Unttled1.Cpp在函数"int main(…)"中:
28 C:\Dev Cpp\project\test\Unttled1.Cpp返回语句,没有值,函数中返回"int"
任何帮助都将不胜感激。
这是我使用的代码(取自微软的例子):
#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) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
更改
void _tmain( int argc, TCHAR *argv[] )
至
int _tmain( int argc, TCHAR *argv[] )
并在程序中返回一个退出代码,即更改
{
printf( "CreateProcess failed (%d).n", GetLastError() );
return;
}
至
{
printf( "CreateProcess failed (%d).n", GetLastError() );
return 1;
}
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译