A limitation of GetEnv(namedenv$) is that you have to know
in advance the name of the enviromental (nameenv$) that
you want the setting for. Some other languages allow you
to sequence the environmentals by a number reference,
beginning with 1. When a Nil string ("") is returned, you
have reached the end of the environmental space.
Note that you can add, delete, or alter the environmental settings by going through the Start/Settings/Control Panel/System/Advanced settings. The ones that appear are
controlled by your profile, so if you are logged in as a
different user, you may somewhat have different settings.
I wrote a version of the GetEnviron function using the
PowerBASIC PB/Win (Previously called PB/DLL) compiler, and
took advantage of the ENVIRON$() function in that language.
The code looked like this:
;note comments shown here with (;), not the {'} used in PB/WIN
;placed in a GetEnviron.BAS file and compiled with PB/Win:
#COMPILE DLL
;canned statements for LIBMAIN call inserted here to load DLL
;actual statements for DLL function below:
FUNCTION GetEnviron ALIAS "GetEnviron" (BYVAL Param1 AS LONG) AS EXPORT STRING
dim Param2 AS STRING
param2=ENVIRON$(param1)
IF LEN(PARAM2) THEN
FUNCTION=param2
ELSE
FUNCTION=CHR$(0)
END IF
END FUNCTION
Then I create a \PBBlitz3D\Userlibs\GetEnviron.decls file with the following in it:
.lib "<path>\GetEnviron.DLL" ;path needed if GetEnviron.DLL not in the UserLibs folder
GetEnviron$(parma1%):GetEnviron
Any and all .DECLS files found in UserLibs are automatically accessed by Pblitz when the IDE starts up.
The term after the colon (:) in the DECLS file is the actual name of the function as reported by the DLL header. Note that the ALIAS in PB/WIN and the name following the : in the .DECLS file must be exactly the same, or no match will be made. If the ALIAS was not used in the DLL source
file, the function name would probably have been rendered
into a C-compatable form, which would be a leading underscore character and the name in lower case -- in this instance, _getenviron.
Depending upon these factors, you could have made the following entry into the DECLS file:
.LIB "<path>\GetEnviron.Dll"
GetEnviron$(param1%):_getenviron
Of particular note is the fact that param1 was passed with
a BYVAL reference. This means the actual value was placed
on the stack and passed, rather than a variable reference.
This avoids the problem of different methods by different
compilers to represent variables. In some compilers, you
can "dereference" a variable by enclosing it in parens (),
meaning that the "equationa" indicated by the () is first
solved and the results (the value) is passed. You might
also use something like parm+0, whifh also forces an
eqpression evaluation before the resulting value is passed.
I would be glad to upload the GetEnviron$(param1%) DLL file that I completed, but to date no-one has explained how to put a binary file into the BlitzBASIC archives. But perhaps this explanation of how to make one and use it with Blitz will be as helpful.