comp.lang.ada
 help / color / mirror / Atom feed
From: tarantripathi@ieee.org (TARAN TRIPATHI)
Subject: Accessing Windows environment vairables in ObjectADA on windows
Date: 15 Oct 2004 00:25:19 -0700
Date: 2004-10-15T00:25:19-07:00	[thread overview]
Message-ID: <b949b6a7.0410142325.3a379563@posting.google.com> (raw)

Hi All,

This is what I have.

I have a win batch file which sets an environment variable say
"TEST_SOURCE_DIR"

setlocal
..
set TEST_SOURCE_DIR=%1
...
endlocal

For the purpose of seeing how to do it I used set TEST_SOURCE_DIR=C:\
on command prompt to set the variable.

I have to access this evironment variable in my ADA code.
This is test code I wrote:

with ADA.Text_IO,System.RTS.Win32;
procedure GetEnvVar is
    EnvVal:String(1..100):=(others=>' ');
    len:System.RTS.Win32.DWORD:=100;
begin
      Len:=System.RTS.Win32.GetEnvironmentVariable("TEST_SOURCE_DIR",EnvVal'Address,Len);
      Ada.Text_IO.Put_Line(EnvVal);
end GetEnvVar;

The GetEnvironmentVariable function is defined in System.RTS32.Win32
packages in Win32INT file.

The problem is that the GetEnvironmentVariable function returns null
for TEST_SOURCE_DIR but gives the correct value for all other Env
variables like HOME, ALLUSERSPROFILE,APPDATA, PROCESSOR_ARCHITECTURE
etc, but never for TEST_SOURCE_DIR.

Also the funnier thing is that if I donot catch the return value of
GetEnvironmentVariable funtion and use it as such
 System.RTS.Win32.GetEnvironmentVariable("TEST_SOURCE_DIR",EnvVal'Address,Len);
I get a compiler error
" Error: line 34 col 19 LRM:5.1(4), Procedure call, entry call, or
code statement expected, Continuing "
which relates to BNF for simple statement. I believe we need not
necessarily capture the return value of any function(?)

Does the variable being local or system variable make any difference?

I googled many a times for this but no help. I've looked around at
FAQ's and the
adahome reference pages, but I haven't found anything.
I an using ObjectAda 7.2 on Windows NT.

I'm not supposed to use florist package or POSIX/ADA interface. Even a
C library is not assured so that I can use #pragma
Interface(C,getenv).
I have to use the GetEnvironmentVariable function. 

Any help or pointers would be appreciated.
Thanx in advance.

Regards,
Taran.



             reply	other threads:[~2004-10-15  7:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-15  7:25 TARAN TRIPATHI [this message]
2004-10-15 10:02 ` Accessing Windows environment vairables in ObjectADA on windows Marius Amado Alves
2004-10-15 10:07 ` Marius Amado Alves
2004-10-15 10:15 ` Marius Amado Alves
     [not found] ` <311c6b78.0410150755.36b2e872@posting.google.com>
2004-10-16  1:18   ` Jeffrey Carter
2004-10-16  3:09 ` Steve
2004-10-18 20:01 ` Frank Beard
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox