c++ - CreateProcess doesn't pass command line argument to new process's main function -


I have some questions about the CreateProcess function. Plz see my CPP files beblow

  // CreateProcess.cpp # included & lt; Stdio.h & gt; # Include & lt; Tchar.h & gt; # Include & lt; Windows.h & gt; # Defined DIR_LEN MAX_PATH + 1 int _tmain (int argc, TCHAR * argv []) {STARTUPINFO si = {0}; PROCESS_INFORMATION pi; Si.cb = Size (C); Si.dwFlags = STARTF_USEPOSITION | STARTF_USESIZE; Si.dwx = 100; Si.dwY = 200; Si.dwXSize = 300; Si.dwYSize = 200; Si.lpTitle = _T ("I'm a Humming"); TCHAR command [] = _T ("adapter process.exa aa bb"); TCHAR CDIR [DIR_LE]; Bull state; GetCurrentDirectory (DIR_LEN, CDIR); _fput (CDIR, stadout); _fputts (_T ("\ n"), stdout); SetCurrentDirectory (_T ("C: \\ WinSystem")); GetCurrentDirectory (DIR_LEN, CDIR); _fputts (cDir, stdout); _fputts (_T ("\ n"), stdout); State = create process (zero, command, zero, zero, true, CREATE_NEW_CONSOLE, NULL, NULL, and SI, and PI); If (state! = 0) _fputts (_T ("build ok! \ N"), stdout); Else _fputts (_T ("Construction Error! \ N"), stdout); _fgettchar (); Return 0; } // Adder ProcessPPP # Include & lt; Stdio.h & gt; # Include & lt; Tchar.h & gt; # Include & lt; Windows.h & gt; Int _tmain (int argc, TCHAR * argv []) {_tprintf (_T ("% s \ n", argv [1])); _tprintf (_T ("% s \ n", argv [2])); DWORD VAL1, VAL 2; Val1 = _ttoi (argv [1]); Val2 = _ttoi (argv [2]); _tprintf (_T ("% d +% d =% d \ n", val1, val2, val1 + val2)); _gettchar (); Return 0; }  

It was OK to create AdderProcess console window after I opened CreateProcess.exe. But there is a problem about passing the main function logic. Argv [1], argv [2]

This AdderProcess.exe is the performance result screen,

   

I do not know why the CreateProcess.exe can not pass arguments in AdderProcess.exe

Why does it not get OP, why is the cause _T the macro is misused

Instead:

  _tprintf (_T ("% d +% d =% d \ n", val1, val2, val1 + val2));  

should be:

  _tprintf (_T ("% d +% d =% d \ n"), val1, val2, val1 + val2 );  

The same error appears in all other rows in _tmain which use _T . _T The macro takes a logic, and it is a string-literal


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -