c++ - CreateProcess() compiling error? -
How do I use the CreateProcess () function, and I'm not very efficient in C ++. I tried to do some things to try, but then it appears that the application does not do what I want to do after this.
What do I have to do to pass "CMD .exe / c ipconfig> c: \ test.txt" to do this and execute it as expected
I The error I am getting (in dev + C ++) are:
6 C: \ Dev-Cpp \ project \ test \ Untitled1.cpp
main function `int main (.
Any help would be greatly appreciated.
Here is the code I used (taken from the example of Microsoft):
#include & lt; Windows.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Tchar.h & gt; Zero _ TMN (Intuarial, TCHR * AGR []) {STARTUPINFO si; PROCESS_INFORMATION pi; Xeromamari (and, shape (SI)); Si.cb = Size (C); Zoramori (and p, sapphire (pi)); // Start the child process if (! CreateProcess (NULL, // a module name (use command line) argv [1], // command line zero, // process handle inheritable tap, // thread handle inheriting Do not FALSE, // set handle legacy incorrect 0, // generate a generator flag, // parents use environment block, NULL, // use parent's initial directory & amp; si, // Indicator STARTUPINFO structure & amp; pi) // Indicator indicator for PROCESS_INFORMATION structure) {pri Ntf ("CreateProcess failed (% d). \ N", GetLastError ()); Return; } // Wait until the child is out of process WaitingCoordenelElectject (PI. Process, exclusive); // Close process and thread handle CloseHandle (pi.hProcess); CloseHandle (pi.hThread); }
change
zero _tmain (int argc , TCHAR * argv [])
to
int _tmain (int argc, TCHAR * argv []) < p> and return an exit code in your program, which is,
{printf ("CreateProcess Fail (% d). \ n", GetLastError ()); Return; }
to
{printf ("Create process failed (% d). \ n", GetLastError ()); Return 1; }
Comments
Post a Comment