This method is most useful for calling EXE.
#include <ShellAPI.h>
stringFile_path = s_run_dir+"\\ConsoleApplication1.exe"; if(!myfile. Isfileexist (File_path)) {return 1; } LPCWSTR Lp_file_path=mystring. Stringtolpcwstr (File_path); Shellexecuteinfo Shexecinfo; Shexecinfo.cbsize=sizeof(Shellexecuteinfo); Shexecinfo.fmask=see_mask_nocloseprocess; Shexecinfo.hwnd=NULL; Shexecinfo.lpverb=NULL; Shexecinfo.lpfile=Lp_file_path; Shexecinfo.lpparameters= __t ("d:\\a.txt d:\\b.txt d:\\c.txt");//Outgoing ParametersShexecinfo.lpdirectory =NULL; Shexecinfo.nshow=Sw_show; Shexecinfo.hinstapp=NULL; BOOL B_ret=shellexecuteex (&shexecinfo); if(B_ret) {//wait for the call to start the EXE shutdown, here to be set to Shexecinfo.fmask = See_mask_nocloseprocess;WaitForSingleObject (shexecinfo.hprocess, INFINITE); } Else { return 2; }
Pass to the console program parameters
#include"stdafx.h"#include<iostream>using namespacestd;int_tmain (intARGC, _tchar*argv[]) { //number of arguments, the first parameter is the path to an executable file intIparamcount =argc; cout<<"Number of parameters:"<< Iparamcount <<Endl; for(inti =0; i < Iparamcount; i++) {cout<< Endl <<"Section"<< i +1<<"a parameter:"; wprintf (Argv[i]); } getchar (); return 0;}
C + + calls external program Exe-shellexecuteex