Get_Environment_String

include vmm.inc

mov     esi, OFFSET32 Variable  ; environment variable name
VMMCall Get_Environment_String

jc      not_found               ; carry set if variable not found
mov     [Value], edx            ; addr. of null-terminated string
 

Returns the value of the specified environment variable. For Windows 95, this service is available following initialization. Uses EDX, Flags.

Variable
Address of a null-terminated string specifying the name of an MS-DOS environment variable. This service is not sensitive to case, so the name may be given in any combination of uppercase and lowercase letters. If zero is passed, the service returns a pointer to the environment block. Additional information about the environment block follows the environment variables comment.

Environment variables, set using the MS-DOS set command, are a limited resource. Although some virtual devices use environment variables as a way to set operating parameters, this is not recommended unless the variable is used by a set of programs, MS-DOS device drivers, and virtual devices.

When zero is passed as the name of the environment variable, a pointer to the 'global environment' is returned in the EDX register. The global environment has the same format as in MS-DOS: A packed array of zero-terminated ASCII strings, each of the form '<variable>=<value>', all terminated by an extra null byte. The VMM also creates a fake 16-byte MS-DOS arena header in front of the environment block so that you can determine its size:

GLOBAL_ENVIRONMENT_HEADER struc
        db        'M'
        dw        0FFFFh
        dw        paraSize            ; Size in paragraphs, not incl. header
        db        11 dup (?)        ; Padding
GLOBAL_ENVIRONMENT_HEADER ends
 

Do not attempt to resize the environment. You may, however, edit the environment, provided you do so during system initialization. Changes to the global environment after system initialization will not take effect the way you expect.

Do not keep pointers into the global environment. The global environment moves around during the running of the system, so any pointer you keep into it may be stale by the time you use it. If you need to retain the value of an environment variable, make a private copy.