UINT WinExec(lpszCmdLine, fuCmdShow) | |||||
LPCSTR lpszCmdLine; | /* address of command line | */ | |||
UINT fuCmdShow; | /* window style for new app. | */ |
The WinExec function runs the specified application.
lpszCmdLine
Points to a null-terminated Windows character string that contains the command line (filename plus optional parameters) for the application to be run. If the string does not contain a path, Windows searches the directories in this order:
1.The current directory.
2.The Windows directory (the directory containing WIN.COM); the GetWindowsDirectory function retrieves the path of this directory.
3.The Windows system directory (the directory containing such system files as GDI.EXE); the GetSystemDirectory function retrieves the path of this directory.
4.The directory containing the executable file for the current task; the GetModuleFileName function retrieves the path of this directory.
5.The directories listed in the PATH environment variable.
6.The directories mapped in a network.
fuCmdShow
Specifies how a Windows application window is to be shown. See the description of the ShowWindow function for a list of the acceptable values for the fuCmdShow parameter. For a non-Windows application, the program-information file (PIF), if any, for the application determines the window state.
The return value identifies the instance of the loaded module, if the function is successful. Otherwise, the return value is an error value less than 32.
The error value may be one of the following:
Value | Meaning |
0 | System was out of memory, executable file was corrupt, or relocations were invalid. |
2 | File was not found. |
3 | Path was not found. |
5 | Attempt was made to dynamically link to a task, or there was a sharing or network-protection error. |
6 | Library required separate data segments for each task. |
8 | There was insufficient memory to start the application. |
10 | Windows version was incorrect. |
11 | Executable file was invalid. Either it was not a Windows application or there was an error in the .EXE image. |
12 | Application was designed for a different operating system. |
13 | Application was designed for MS-DOS 4.0. |
14 | Type of executable file was unknown. |
15 | Attempt was made to load a real-mode application (developed for an earlier version of Windows). |
16 | Attempt was made to load a second instance of an executable file containing multiple data segments that were not marked read-only. |
19 | Attempt was made to load a compressed executable file. The file must be decompressed before it can be loaded. |
20 | Dynamic-link library (DLL) file was invalid. One of the DLLs required to run this application was corrupt. |
21 | Application requires Microsoft Windows 32-bit extensions. |
The LoadModule function provides an alternative method for running an application.
The following example uses the WinExec function to run DRAW.EXE:
WORD wReturn;
char szMsg[80];
wReturn = WinExec("draw", SW_SHOW);
if (wReturn < 32) {
sprintf(szMsg, "WinExec failed; error code = %d", wReturn);
MessageBox(hwnd, szMsg, "Error", MB_ICONSTOP);
}
else {
sprintf(szMsg, "WinExec returned %d", wReturn);
MessageBox(hwnd, szMsg, "", MB_OK);
}
GetModuleFileName, GetSystemDirectory, GetWindowsDirectory, LoadModule, ShowWindow