How to open the specified plan or file in VC...txt
- richwichmann94ybqy
- Jun 13, 2020
- 4 min read
The best way to open the specified program or file (transfer) in VC [Category: Improvement Information] [Read: 1799] [Date: 2008-11-11] [From: Piao Xue Studio] Use WinExec
⑴ Function prototype:
UINTWinExec(LPCSTRlpCmdLine, UINTuCmdShow);
⑵ Parameters:
lpCmdLine: points to a null-terminated string, which consists of the command line on the application to become executed (file name plus optional parameters).
uCmdShow: Defines how the window of your Windows application is displayed, and supplies the value from the wShowWindow member of your STARTUPINFO parameter for the CreateProcess function.
⑶ Return value:
When the function call succeeds, the return worth is higher than 31. When the function fails, the return worth is amongst the following:
① 0: The method memory or resources are exhausted.
② ERROR_BAD_FORMAT: The EXE file is invalid (non-Win32.EXE or .EXE image error).
③ ERROR_FILE_NOT_FOUND: The specified file was not identified.
④ ERROR_PATH_NOT_FOUND: The specified path was not discovered.
Although Microsoft believes that WinExec is outdated, in numerous cases, basic WinExec functions are still the ideal solution to run new applications. To simply pass the command line as the initial parameter, you also need to decide the best way to display the second parameter with the system (the system could ignore it). Ordinarily, set it to SW_SHOW, you may also try SW_MINIMIZED or SW_MAXIMIZED. WinExec will not enable all the options obtained with CreateProcess, and it can be indeed straightforward.
Use ShellExecute command
⑴ Function prototype:
Quote:HINSTANCEShellExecute(HWNDhwnd,LPCTSTRlpOperation,LPCTSTRlpFile,LPCTSTRlpParameters,LPCTSTRlpDirectory,INTnShowCmd);
⑵ Parameters:
hwnd: Point for the window deal with of the parent window. This window receives any facts box generated by the application.
lpOperation: a null-terminated string address, this string specifies the operation to become performed. The following operation strings are valid:
'open' This function opens the file specified by the parameter lpFile. This file is usually an executable file, a document file, or possibly a folder.
'print' This function prints the file specified by the parameter lpFile. This file should really be a document file. If this file is definitely an executable file, open this file.
'explore' This function searches the folder specified by the parameter lpFile, this file should be a document file,
This parameter may be empty. Within this case, the function is utilised to open the file specified by the parameter lpFile.
lpFile: A null-terminated string address. This string specifies the file to be opened or printed or the folder to become opened or searched.
lpParameters: When the parameter lpFile specifies an executable file, lpParameters can be a null-terminated string address. This string specifies the parameters to be passed towards the application. If lpFile specifies a document file, lpParameters really should be empty.
lpDirectory: a null-terminated string address, this string specifies the default directory.
nShowCmd: If lpFile specifies an executable file, nShowCmd indicates ways to show it when the application is opened. If lpFile specifies a document file, nShowCmd must be empty.
⑶ Return value:
In the event the function call succeeds, the return value is higher than 32, otherwise it truly is an error value much less than or equal to 32.
Note: You could use this function to open or search a shell folder. Open the folder in any of the following forms:
Code:
ShellExecute(handle,NULL,path_to_folder,NULL,NULL,SW_SHOWNORMAL);
Quote:ShellExecute(manage,'open',path_to_folder,NULL,NULL,SW_SHOWNORMAL);
Search folder, available inside the following form
ShellExecute(deal with,'explore',path_to_folder,NULL,NULL,SW_SHOWNORMAL);
The ShellExecute command is outdated but effortless to receive. This command tends to make a request to open, browse, or print a document or folder towards the command interpreter. Though ShellExecute is usually employed to run the system, it generally sends only the document name, along with the command interpreter decides which program to run. Moreover, the ShellExecute command is extremely useful when opening directory folders.
⑷ Program example
The following makes use of an instance to illustrate the use of WinExec and ShellExecute. The following system features a sample console plan, which utilizes two unique procedures to open a text file. The following system uses WinExec and clearly specifies the use of the Notepad system. Then, use ShellExecute to open the text file.
free unlimited data recovery software :#includewindows.h
voidmain(intargc,char*argv[])
coutOpeningwithWinExec\
if(WinExec(notepadreadme.txt,SH_SHOW)32)
MessagBox(NULL, CantWinExec, NULL, MB_OK);
coutPressEnter\
MessagBox(NULL, PressOKtocontinue, ProgrmLaunched, MB_OK);
coutOpeningwithShellExecute\
if(ShellExecute(NULL,open,readme.txt,NULL,NULL,SW_SHOW)(Deal with)32)
MessagBox(NULL,CantShellExecute\
,NULL,MB_OK);
Use the CreateProcess command
⑴ Function prototype:
Code:BOOLCreateProcess(
LPCTSTRlpApplicationName,
LPTSTRlpCommandLine,
LPSECURITY_ATTRIBUTESlpProcessAttributes,
LPSECURITY_ATTRIBUTESlpThreadAttributes,
BOOLbInheritHandles,
DWORDdwCreationFlags,
LPVOIDlpEnvironment,
LPCTSTRlpCurrentDirectory,
LPSTARTUPINFOlpStartupInfo,
LPPROCESS_INFORMATIONlpProcessInformation
⑵ Parameters:
lpApplicationName: points to a null-terminated string, he specifies the module to become executed
lpCommandLine: points to a null-terminated string, which defines the command line to become executed.
lpProcessAttributes: points to a SECURITY_ATTRIBUTES structure, which determines whether or not the returned handle may be inherited by the child process.
lpThreadAttributes: points to a SECURITY_ATTRIBUTES structure, which determines irrespective of whether the returned manage is usually inherited by the kid procedure.
bInheritHandles, indicates whether the new approach inherits the manage from the calling procedure.
dwCreationFlags: Define extra flags that manage the creation of priority classes and processes.
lpEnvironment: Point for the environment block of a new method.
lpCurrentDirectory: points to a null-terminated string, which defines the current drive and existing directory on the youngster method.
lpStartupInfo: points to a STARTUPINFO structure, which defines how the main window of the new process might be displayed.
lpProcessInformation: points towards the PROCESS_INFORMATION structure, which accepts representation information concerning the new procedure.
⑶ Return worth:
If the function call succeeds, the return value will not be 0; if the function contact fails, the return value is 0.
ShellExecute and WinExec commands are applied for basic jobs. If you need to completely manage a new course of action, you need to get in touch with CreateProcess.
Amongst data recovery software free download , the parameter lpStartupInfo is actually a STARTUPINFO structure. Can be utilised to set the title of your console, the initial size and position in the new window, and redirect typical input and output. New applications can normally ignore most of these information products if they select to do so. data recovery within the structure can be specified, which has indicated the information segment to be set. At times, in the event you do not wish to set any information and facts, you have to also pass a valid pointer for the empty structure (ensure to set the size to cb, and set the dwFlags member to 0). The parameter lpProcessInformation returns the procedure and thread handles, as well as consists of the process and thread ID. These handles possess the access specified inside the parameters lpProcessAttributes and lpThreadAttributes.
Note that some parameters for CreateProcess are certain towards the console application, whilst other parameters are beneficial for several applications. In most circumstances, it is not necessary to fill inside the STARTUPINFO structure, however it has to be offered anyway. The return worth is Boolean, along with the return value of true interest happens within the structure passed as a parameter (PROCESS_INFORMATION). CreateProcess returns the method ID and its manage inside the structure, too as the initial thread ID and its handle. You'll be able to send the ID to other processes or make use of the deal with to control the new procedure.
Comments