GUI ScreenIO for Windows

 ScreenIO.com


GetEnvironmentVariable

This API returns the value of an environmental variable. Environmental Values many be set via SET statements in batch files, or in the control panel of Windows 2000 or XP.

Why use this?

Most compilers have the utilities or APIs to return environmental variable values. However, these utilities are not transportable to another compiler, nor are they client/server aware, meaning you can not return values from the client unless you uses this API.

Client/Server issues

This API will return the variable from the client.  You can optionally return variables from the server if you can preceded the API call with the following Set statement:

     SET WIN32API-EXECUTE-API-ON-SERVER TO TRUE

Files

Files available to copy to your system:

Usage

     COPY WIN32API.
     COPY ENVIRON.


     
* ------------------------: Call the API.
*

     MOVE LENGTH OF ENV-VARIABLE-VALUE  TO ENV-VALUE-LENGTH
     MOVE LOW-VALUES TO ENV-VARIABLE-VALUE
*                         : This is the environment variable name
*                         : we want to retrieve
     MOVE "TEMP" TO ENV-VARIABLE-NAME
* ------------------------: Call the API to get the value
*
     SET API-GETENVIRONMENTVARIABLE TO TRUE.
     CALL 'GSWINAPI' USING WIN32API-PARMS
                           ENV-VALUE-LENGTH
                           ENV-VARIABLE-NAME
                           ENV-VARIABLE-VALUE
                           WIN32API-D
                           WIN32API-E
                           WIN32API-F.

Parameters specific to this function

ENV-VALUE-LENGTH

This field must be set to the length of the field which will receive the value of the environmental variable.  The ENVIRON copybook supplies a generic field of 1024 bytes, but since environmental values can be up to 32k bytes, you may have to substitute a different field for ENV-VARIABLE-VALUE.  In any event, this field must be set to the length of your receiving field.  If your receiving field is too short, this API call will fail, (WIN32API-FAILED will be true)  and this field will contain the required length.

ENV-VARIABLE-NAME 

This field should contain the name of the environmental variable you want to retrieve.  It is case insensitive.

ENV-VARIABLE-VALUE

This field (or any alternative field you wish to use) will receive the value of the environmental variable.  It will be a null terminated string.  The length of this string will be returned in WIN32API-RC.

WIN32API-PARMS - Used in all GSWINAPI calls

This argument is standard for all CALLs to GSWINAPI. It is used to select the desired API or function, and to return the status of the operation.

WIN32API-RC

Used to return the status of a call to GSWINAPI.  A value of zero is a failure, any other value indicates success. 

Recommended usage is to test the 88-level value WIN32API to see if it worked, then to use the text error message to see why it failed.

* ------------------------: If function failed,
*                         :   display the error in a message box.
*
     IF WIN32API-FAILED
       MOVE WIN32API-ERROR-TEXT TO panel-MESSAGE-TEXT
       SET panel-MESSAGE-IN-MESSAGEBOX TO TRUE.

WIN32API-ERROR-CODE

Error code that was returned by Windows.  This is not generally useful unless you have the Windows Platform SDK documentation available to you.

WIN32API-ERROR-TEXT

Plain-text error message that describes why the operation failed.

WIN32API-A through WIN32API-F

The number of these present varies depending on how many arguments are used by the desired function.  These are not used, but must be present because this CALL requires seven arguments.


2000-2006 Norcom, all rights reserved 

TOC

Send feedback to Norcom