> 好不容易,終於找到執行DOS的執行檔的指令,但是那本書可真好心,只告
>訴我這個指令,卻沒告訴我用法,害我又陷於一片迷網,趕緊上來請教一下各
>位,教我一下這個指令的用法好嗎?舉例,我要執行c:\fuzzy\dsp_s.exe
>那我要怎麼使用WinExec(......) ,還有,若是我在執行時,不希望全影幕在DOS
>下,希望能在視窗內(就是按ctrl+enter回到WIN時,DOS模式即化視窗,現在
>我要的是不須按ctrl+enter,直接就 是WIN下開個DOS模式去執行那程式)
> 謝謝各位的幫忙
技術手冊中寫到:
UINT WinExec(lpszCmdLine, fuCmdShow)
LPCSTR lpszCmdLine; /* address of command line */
UINT fuCmdShow; /* window state of new app. */
The WinExec function runs the specified application.
Parameter Description
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.
Returns
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.
Errors
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.
Comments
The LoadModule function provides an alternative method for running an
application.
Example
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);
}
See Also
GetModuleFileName, GetSystemDirectory, GetWindowsDirectory,
LoadModule, ShowWindow
=====================================
Shelly Wu
e-mail: ev...@ms1.hinet.net
=====================================