Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 13 JUN 2002 06:39:58PM Jonathan Bird wrote:

Short of using a batch file to pipe out the DOS environment to a file and reading the file, is there any way for OI to read environment variables?

J


At 13 JUN 2002 07:21PM Oystein Reigem wrote:

Jonathan,

There is a Windows function GETENVIRONMENTVARIABLE. Do a search.

- Oystein -


At 13 JUN 2002 08:29PM Richard Hunt wrote:

Jonathan,

You can call a DLL function (GetEnvironmentVariable or might be GetEnvironmentVariableA) from your stored proceedure (basic program). You might have to set up a DLL.

Follow these steps to crete the prototype record…

1) Create a row DLL_ONE (you can call it anything you want) by using the system editor. It should look like this…

KERNEL32

SHORT PASCAL GetEnvironmentVariableA(LPCHAR,LPCHAR,SHORT)

2) At the system editor exec line type RUN DECLARE_FCNS "DLL_ONE"

Now you can declare the function and call it like this…

DECLARE FUNCTION GETENVIRONMENTVARIABLEA

RESULT='DECLARE FUNCTION GETENVIRONMENTVARIABLEA

RESULT='

VARIABLE=windir':CHAR(0)

BUFFER=STR(CHAR(0),1000)

SIZE=1000

RESULT=GETENVIRONMENTVARIABLEA(VARIABLE,BUFFER,SIZE)

This will return…

RESULT=8

BUFFER=C:\WINNT' with CHAR(0)'s appended.


At 18 JUN 2002 07:36PM Jonathan Bird wrote:

Thanks Richard.

But calling kernel32 does not work from OI 16-bit. Is there another way, or another (16-bit) DLL to get the environment variables from?

J


At 19 JUN 2002 06:16AM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:

Check out this link

The Sprezzatura Group

World leaders in all things RevSoft

www.sprezzatura.com_zz.jpg


At 19 JUN 2002 10:39PM Jonathan Bird wrote:

Yes, I already had a look at that link. Its all a bit Greek to me. How does it help? Perhaps I'm being a bit thick here ????

J


At 20 JUN 2002 09:36AM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:

J,

Hey, I never realised I could speak Greek! :-)

OK, The first step is to prototype the GetDOSEnvironment function that's exported from the Windows Kernel which do you like so:

1) In the System Editor open the DLL_KERNEL record from the SYSPROCS table.

2) Add the following line:

 LPVOID PASCAL GetDOSEnvironment( VOID )

3) Save the record and in the system editor Exec line type

 RUN DECLARE_FCNS 'DLL_KERNEL'

and execute it.

You should now be able to call the GetDOSEnvironment function from Basic+. Because of the way it works however you need to use some tricks to get the information back which is where the example function I wrote comes in:

declare function GetDOSEnvironment
envStr = ""
envLen = 2
lpEnv  = GetDOSEnvironment()
eof    = 0
loop
  envStr=getValue( lpEnv , Char, envLen )
  if envStr-2,2=\0000\ then
    // End of Environment variables
    eof=1
    envStr-2,2="
  end else
    envLen += 1
  end
until eof
repeat
convert \00\ to @Fm in envStr
* // EnvStr now contains a dynamic array of environment variables

Try it and see. What happens is that you get a pointer back that points to the start of the environment strings. They are CHar(0) delimited and you know when you've got to the end because you come to two char(0)'s together. As we are playing with pointers we have to use GetValue to de-reference them and get to the data they point at, but as we don't know the length we have to be careful we don't go too far and cause a GPF, hence checking 2 bytes at a time.

The Sprezzatura Group

World leaders in all things RevSoft

www.sprezzatura.com_zz.jpg


At 20 JUN 2002 05:43PM Jonathan Bird wrote:

Thanks,

My Greek is improving, a little. What I was missing was:

1) In the System Editor open the DLL_KERNEL record from the SYSPROCS table.

The rest made sense. Thanks a lot. All works now.

J

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/5d2f83edd1e59a1c85256bd7007c8248.txt
  • Last modified: 2024/01/04 21:00
  • by 127.0.0.1