Overview
The following program is a window popup issue that resolves when you call the system () function under Windows
Header file
#include <windows.h>
Source
/** * @brief ordinary character-width character * * @param lpcszstr Ordinary character * @param lpwszstr wide character after conversion * @param dwsize the size of the buffer that stores the wide character * * @return*/BOOL Mbytetowchar (LPCSTR lpcszstr, LPWStr lpwszstr, DWORD dwsize) {//Get The required size of the buffer that receives the Unicode//string.DWORD dwminsize;dwminsize= MultiByteToWideChar (CP_ACP,0, Lpcszstr,-1Null0);if(Dwsize <dwminsize) {returnFALSE;}//Convert headers from ASCII to Unicode.MultiByteToWideChar (CP_ACP,0, Lpcszstr,-1, Lpwszstr, dwminsize); returnTRUE;}
/** * @brief wide character to normal character * * @param lpcwszstr wide character * @param lpszstr normal character after conversion * @param dwsize stores the buffer size of ordinary characters * * @return*/BOOL wchartombyte (lpcwstr lpcwszstr, LPSTR Lpszstr, DWORD dwsize) {DWORD Dwminsize;dwminsize= WideCharToMultiByte (CP_OEMCP,0, lpcwszstr,-1Null0, null,false);if(Dwsize <dwminsize) {returnFALSE;} WideCharToMultiByte (CP_OEMCP,0, lpcwszstr,-1, lpszstr,dwsize,null,false);returnTRUE;}
/** * @brief * winexec and ShellExecute Two functions do not wait for the execution of the command to complete, * will cause the file did not extract finished, do not meet our needs * RET=WINEXEC (cmd,sw_hide); ShellExecute (HWND) "Open", Lpcwstr (cmd), NULL, null,null,sw_hide); * * The system function call can, but there will be a window popup * ret = System (CMD); * * in the following way * * @param cmd cannot appear in the > symbol * * @return **/intNb_system (Char*cmd) {wchar_t cmd_w[2048] = {0}; Mbytetowchar (cmd, Cmd_w,sizeof(CMD_W)/sizeof(cmd_w[0])); Startupinfo si; ZeroMemory (&si,sizeof(SI)); SI.CB=sizeofStartupinfo; Process_information Pi={0};if(CreateProcess (Null,cmd_w,null,null,true,normal_priority_class | create_no_window,null,null,&si,&pi)) {//wait for the process to finish executingWaitForSingleObject (pi.hprocess, INFINITE);//Freeing ResourcesCloseHandle (pi.hprocess); CloseHandle (Pi.hthread); }Else{//failed to runreturn-1;}return 0;}
Test
int Main () { Nb_system ("dir");}
Windows hides the system function pop-up window