Jump to content

DosGetEnv: Difference between revisions

From EDM2
No edit summary
Ak120 (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Legacy
{{Legacy
|RepFunc=N/A
|RepFunc=N/A
|Remarks=This function has been eliminated since OS/2 2.0
|Remarks=This function has been eliminated since OS/2 2.0. [http://books.google.com/books?id=u7WbsmbttwYC&pg=PT372]
}}
}}
This call returns the address of the process environment string for the current process.
This call returns the address of the process environment string for the current process.
Line 13: Line 13:


==Return Code==
==Return Code==
rc (USHORT) - return
;rc (USHORT) - return:Return code descriptions are:
Return code descriptions are:
* 0 NO_ERROR
* 0         NO_ERROR
*12 ERROR_INVALID_ACCESS
* 12       ERROR_INVALID_ACCESS  


==Remarks==
==Remarks==
DosGetEnv can be used by dynamic link library routines that need to determine the environment for the current process.
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.
When a process issues [[DosExecPgm]] to start another process, the program that receives control is returned a pointer to the environment segment.


==Example Code==
==Bindings==
===C Binding===
===C===
<PRE>
<PRE>
#define INCL_DOSMISC
#define INCL_DOSMISC
Line 30: Line 29:
USHORT  rc = DosGetEnv(EnvSegment, CmdOffset);
USHORT  rc = DosGetEnv(EnvSegment, CmdOffset);


PUSHORT         EnvSegment;    /* Selector (returned) */
PUSHORT EnvSegment;    /* Selector (returned) */
PUSHORT         CmdOffset;    /* Command line offset (returned) */
PUSHORT CmdOffset;    /* Command line offset (returned) */
 
USHORT  rc;            /* return code */
</PRE>
 
===MASM===
<PRE>
EXTRN  DosGetEnv:FAR
INCL_DOSMISC      EQU 1
 
PUSH@  WORD    EnvSegment  ;Selector (returned)
PUSH@  WORD    CmdOffset    ;Command line offset (returned)
CALL  DosGetEnv


USHORT          rc;            /* return code */
Returns WORD
</PRE>
</PRE>


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.  
==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>
<PRE>
#define INCL_DOS
#define INCL_DOS
Line 44: Line 56:
main()
main()
{
{
   SEL      EnvSel;             /* Environment segment selector
   SEL      EnvSel;       /* Environment segment selector (returned) */
                                    (returned) */
   USHORT    CmdOffset;     /* Offset into env. seg. of command line (returned) */
   USHORT    CmdOffset;           /* Offset into env. seg. of command line
   PSZ FAR  *Commandline; /* Pointer made by EnvSel and CmdOffset */
                                    (returned) */
   USHORT    Version;       /* Version numbers (returned) */
   PSZ FAR  *Commandline;       /* Pointer made by EnvSel and CmdOffset */
   BYTE      MajorVer;     /* Major version number */
   USHORT    Version;             /* Version numbers (returned) */
   BYTE      MinorVer;     /* Minor version number */
   BYTE      MajorVer;           /* Major version number */
   USHORT    rc;           /* return code */
   BYTE      MinorVer;           /* Minor version number */
   USHORT    rc;                 /* return code */


   /** Locate environment segment and offset of command line. **/
   /** Locate environment segment and offset of command line. **/
   if(!(rc=DosGetEnv(&EnvSel,      /* Env. seg. selector (returned) */
   if(!(rc=DosGetEnv(&EnvSel,      /* Env. seg. selector (returned) */
                     &CmdOffset)))  /* Offset of command line
                     &CmdOffset)))  /* Offset of command line (returned) */
                                          (returned) */
     printf("Environment located; selector is %x offset is %x\n", EnvSel,
     printf("Environment located; selector is %x offset is %x\n", EnvSel,
             CmdOffset);
             CmdOffset);


   /** Use a macro to make a far pointer out of selector:offset pair.**/
   /** Use a macro to make a far pointer out of selector:offset pair. **/
   /** Notice the far-string pointer specification (%Fs) used to print **/
   /** Notice the far-string pointer specification (%Fs) used to print **/


Line 79: Line 88:
</PRE>
</PRE>


===MASM Binding===
[[Category:Dos16]]
<PRE>
EXTRN  DosGetEnv:FAR
INCL_DOSMISC      EQU 1
 
PUSH@  WORD    EnvSegment    ;Selector (returned)
PUSH@  WORD    CmdOffset    ;Command line offset (returned)
CALL  DosGetEnv
 
Returns WORD
</PRE>
==Related Functions==
*
 
[[Category:Dos]]

Latest revision as of 00:31, 5 October 2023

Legacy Function Warning
It is recommended to use a newer replacement for this function.
Replacement: N/A
Remarks: This function has been eliminated since OS/2 2.0. [1]

This call returns the address of the process environment string for the current process.

Syntax

DosGetEnv (EnvSegment, CmdOffset)

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
Return code descriptions are:
  • 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

#define INCL_DOSMISC

USHORT  rc = DosGetEnv(EnvSegment, CmdOffset);

PUSHORT EnvSegment;    /* Selector (returned) */
PUSHORT CmdOffset;     /* Command line offset (returned) */

USHORT  rc;            /* return code */

MASM

EXTRN  DosGetEnv:FAR
INCL_DOSMISC      EQU 1

PUSH@  WORD    EnvSegment   ;Selector (returned)
PUSH@  WORD    CmdOffset    ;Command line offset (returned)
CALL   DosGetEnv

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.

#define INCL_DOS
#include <os2.h>
#define ENVVARNAME "PATH"

main()
{
  SEL       EnvSel;        /* Environment segment selector (returned) */
  USHORT    CmdOffset;     /* Offset into env. seg. of command line (returned) */
  PSZ FAR   *Commandline;  /* Pointer made by EnvSel and CmdOffset */
  USHORT    Version;       /* Version numbers (returned) */
  BYTE      MajorVer;      /* Major version number */
  BYTE      MinorVer;      /* Minor version number */
  USHORT    rc;            /* return code */

  /** Locate environment segment and offset of command line. **/
  if(!(rc=DosGetEnv(&EnvSel,       /* Env. seg. selector (returned) */
                    &CmdOffset)))  /* Offset of command line (returned) */
    printf("Environment located; selector is %x offset is %x\n", EnvSel,
            CmdOffset);

  /** Use a macro to make a far pointer out of selector:offset pair.  **/
  /** Notice the far-string pointer specification (%Fs) used to print **/

  Commandline = MAKEP(EnvSel, CmdOffset);
  printf("Command entered is %Fs.\n", Commandline);

  /** Obtain and print version info; use macros to extract info. **/
  /** We need to divide by 10 to obtain true version numbers.    **/

  if(!(rc=DosGetVersion(&Version)))
  {
    MajorVer = HIBYTE(Version) / 10;
    MinorVer = LOBYTE(Version) / 10;
    printf("This is OS/2 version %d.%d\n", MajorVer, MinorVer);
  }
}