Article View: de.comp.lang.c++
Article #2089Re: Windows Programme aus C++ starten
From: Gerhard Loithaler
Date: Fri, 12 Apr 1996 10:01
Date: Fri, 12 Apr 1996 10:01
125 lines
4422 bytes
4422 bytes
office@schwarzmueller.co.at wrote:
>
> Ich benutze den spawnlp() - Befehl um ein Windows-exe zu starten.
> Nach dem Start des aufgerufenen Programms bekomme ich den Fehler:
> "Allgemeine Schutzverletzung", oder "Fehler im Anwendungsprogramm"
> im aufrufenden Programm.
> Mein Compiler: Symantec C++ V 7.0
Diese Funktionen funktionieren unter Windows nicht. Verwende
stattdessen die Funktion:
WinExec (3.0)
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
Mfg
Gerhard.
Technical Details
Message-ID:
<316E29EE.2011@munich.ixos.de>Path:
arc1-ca.pugleaf.net!munich.ixos.de!newsReferences:
<4kkpu2$gtk@news.Austria.EU.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!munich.ixos.de!news From: Gerhard Loithaler <Gerhard.Loithaler@munich.ixos.de> Newsgroups: de.comp.lang.c++ Subject: Re: Windows Programme aus C++ starten Date: Fri, 12 Apr 1996 12:01:18 +0200 Organization: iXOS Software GmbH Distribution: world Message-ID: <316E29EE.2011@munich.ixos.de> References: <4kkpu2$gtk@news.Austria.EU.net> NNTP-Posting-Host: voyageur.munich.ixos.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.0 (WinNT; I)