no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | en:docs:fapi:dosgetenv [2018/08/31 08:20] – created prokushev | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | |||
+ | This call returns the address of the process environment string for the current process. | ||
+ | |||
+ | ==Syntax== | ||
+ | | ||
+ | |||
+ | ==Parameters== | ||
+ | ;EnvSegment (PSEL) - output : Address of the selector for the environment segment. | ||
+ | ;CmdOffset (PUSHORT) - output : Address of the offset to the command line within the environment segment. | ||
+ | |||
+ | ==Return Code== | ||
+ | ;rc (USHORT) - return: | ||
+ | * 0 NO_ERROR | ||
+ | * 12 ERROR_INVALID_ACCESS | ||
+ | |||
+ | ==Remarks== | ||
+ | DosGetEnv can be used by dynamic link library routines that need to determine the environment for the current process. | ||
+ | |||
+ | When a process issues [[DosExecPgm]] to start another process, the program that receives control is returned a pointer to the environment segment. | ||
+ | |||
+ | ==Bindings== | ||
+ | ===C Binding=== | ||
+ | <PRE> | ||
+ | #define INCL_DOSMISC | ||
+ | |||
+ | USHORT | ||
+ | |||
+ | PUSHORT EnvSegment; | ||
+ | PUSHORT CmdOffset; | ||
+ | |||
+ | USHORT | ||
+ | </ | ||
+ | |||
+ | ===MASM=== | ||
+ | <PRE> | ||
+ | EXTRN DosGetEnv: | ||
+ | INCL_DOSMISC | ||
+ | |||
+ | PUSH@ WORD EnvSegment | ||
+ | PUSH@ WORD CmdOffset | ||
+ | CALL | ||
+ | |||
+ | Returns WORD | ||
+ | </ | ||
+ | |||
+ | ==Example Code== | ||
+ | The following example shows how one may obtain information for program initialization. The program locates the environment segment and prints the name of the command from the command line. It then obtains the OS/2 version number and prints it. | ||
+ | <PRE> | ||
+ | #define INCL_DOS | ||
+ | #include < | ||
+ | #define ENVVARNAME " | ||
+ | |||
+ | main() | ||
+ | { | ||
+ | SEL | ||
+ | USHORT | ||
+ | PSZ FAR | ||
+ | USHORT | ||
+ | BYTE MajorVer; | ||
+ | BYTE MinorVer; | ||
+ | USHORT | ||
+ | |||
+ | /** Locate environment segment and offset of command line. **/ | ||
+ | if(!(rc=DosGetEnv(& | ||
+ | & | ||
+ | printf(" | ||
+ | CmdOffset); | ||
+ | |||
+ | /** Use a macro to make a far pointer out of selector: | ||
+ | /** Notice the far-string pointer specification (%Fs) used to print **/ | ||
+ | |||
+ | Commandline = MAKEP(EnvSel, | ||
+ | printf(" | ||
+ | |||
+ | /** Obtain and print version info; use macros to extract info. **/ | ||
+ | /** We need to divide by 10 to obtain true version numbers. | ||
+ | |||
+ | if(!(rc=DosGetVersion(& | ||
+ | { | ||
+ | MajorVer = HIBYTE(Version) / 10; | ||
+ | MinorVer = LOBYTE(Version) / 10; | ||
+ | printf(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ====== Note ====== | ||
+ | |||
+ | Text based on [[http:// | ||
+ | |||
+ | {{page> | ||
+ | |||