dos12.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DosGetEnv (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSMISC
 
USHORT DosGetEnv(pselEnviron, pusOffsetCmd)
PUSHORT pselEnviron;     /* pointer to variable for selector */
PUSHORT pusOffsetCmd;    /* pointer to variable for offset   */
 
The DosGetEnv function retrieves the address of the process's environment
and an offset into the environment where the command line is stored that was
used to start the process. This offset can be used to retrieve command-line
arguments.
 
The environment is one or more null-terminated strings that name and define
the environment variables available to the current process. The command-line
string is a single null-terminated string that is a copy of the command line
that was used to run the process.
 
The DosGetEnv function is a family API function.
 
Parameter     Description
────────────────────────────────────────────────────────────────────────────
 
pselEnviron   Points to the variable that receives the environment's segment
              selector. The environment begins in the first byte of the
              segment identified by this parameter.
 
pusOffsetCmd  Points to the variable that receives the offset from the
              beginning of the specified segment to the beginning of the
              command line.
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be the following:
 
     ERROR_INVALID_ACCESS
 
Comments
 
Each string in the environment has the following form:
 
    stringname=value
 
Each environment string ends with a null character. The last string is
followed by an additional null character to indicate the end of the
environment. The two null characters are followed by the command-line
string.
 
The DosGetEnv function is typically used to retrieve the command-line
arguments. Although DosGetEnv can be used to retrieve a single environment
variable, an easier way to do this is to call the DosScanEnv function.
 
Example
 
This example calls the DosGetEnv function to retrieve the selector to the
environment and the offset to the argument table within the environment. The
pszEnviron parameter points to the beginning of the environment, and the
pszArgument parameter points to the beginning of the argument table.
 
PSZ pszEnviron, pszArgument;
SEL selEnviron;
USHORT usOffsetCmd;
DosGetEnv(&selEnviron, &usOffsetCmd);
pszEnviron = MAKEP(selEnviron, 0);
pszArgument = MAKEP(selEnviron, usOffsetCmd);
 
See Also
 
DosExecPgm, DosScanEnv