* Re: Accessing Windows environment vairables in ObjectADA on windows
2004-10-15 7:25 Accessing Windows environment vairables in ObjectADA on windows TARAN TRIPATHI
@ 2004-10-15 10:02 ` Marius Amado Alves
2004-10-15 10:07 ` Marius Amado Alves
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marius Amado Alves @ 2004-10-15 10:02 UTC (permalink / raw)
To: comp.lang.ada
> I believe we need not
> necessarily capture the return value of any function(?)
The return value of an Ada function must always be catched.
Ada is different from C in this respect. Ada has procedures and
functions. They are colectively called "subprograms".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Accessing Windows environment vairables in ObjectADA on windows
2004-10-15 7:25 Accessing Windows environment vairables in ObjectADA on windows TARAN TRIPATHI
2004-10-15 10:02 ` Marius Amado Alves
@ 2004-10-15 10:07 ` Marius Amado Alves
2004-10-15 10:15 ` Marius Amado Alves
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marius Amado Alves @ 2004-10-15 10:07 UTC (permalink / raw)
To: comp.lang.ada
> Len:=System.RTS.Win32.GetEnvironmentVariable("TEST_SOURCE_DIR",EnvVal'Address,Len);
This is terribly C-ish and unlike the Ada way.
A proper Ada subprogram for this will have a prototype like
function GetEnvironmentVariable
(Name : String) return String;
or
procedure GetEnvironmentVariable
(Name : String; Value : out Unbounded_String);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Accessing Windows environment vairables in ObjectADA on windows
2004-10-15 7:25 Accessing Windows environment vairables in ObjectADA on windows TARAN TRIPATHI
2004-10-15 10:02 ` 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>
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Marius Amado Alves @ 2004-10-15 10:15 UTC (permalink / raw)
To: comp.lang.ada
> The problem is that the GetEnvironmentVariable function returns null
Are you sure this function returns an access value?
> 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.
Have you tried:
- creating a global variable
- create the variable via control panel
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <311c6b78.0410150755.36b2e872@posting.google.com>]
* Re: Accessing Windows environment vairables in ObjectADA on windows
2004-10-15 7:25 Accessing Windows environment vairables in ObjectADA on windows TARAN TRIPATHI
` (3 preceding siblings ...)
[not found] ` <311c6b78.0410150755.36b2e872@posting.google.com>
@ 2004-10-16 3:09 ` Steve
2004-10-18 20:01 ` Frank Beard
5 siblings, 0 replies; 7+ messages in thread
From: Steve @ 2004-10-16 3:09 UTC (permalink / raw)
Here is an example that works with ObjectAda 7.2.2:
with ADA.Text_IO;
with Win32;
with Win32.WinBase;
with Interfaces.C;
with Interfaces.C.Strings;
procedure GetEnvVar is
use type interfaces.c.unsigned_long;
use type interfaces.c.size_t;
EnvVar : aliased Interfaces.C.Char_Array := Interfaces.C.To_C(
"TEST_SOURCE_DIR" );
EnvVal : aliased Interfaces.C.Char_Array(0..99);
len : Win32.DWORD;
last : Interfaces.C.size_t;
begin
Len:=100;
Len:=Win32.WinBase.GetEnvironmentVariable(
EnvVar(0)'unchecked_access,
EnvVal(0)'unchecked_access,
EnvVal'Length);
if Len > 0 then
last := Interfaces.C.size_t( Len - 1 );
Ada.Text_IO.Put_Line( Interfaces.C.To_Ada( EnvVal(0..last) &
Interfaces.C.NUL ) );
else
Ada.Text_IO.Put_Line( "Env var not found" );
end if;
end GetEnvVar;
You'll need to include:
c:\program files\aonix\objectada\win32ada\binding\lib
In the "Normal" directory links, and:
c:\program files\aonix\objectada\apilib
In the "Linker only" directory links for this example to work.
Steve
(The Duck)
"TARAN TRIPATHI" <tarantripathi@ieee.org> wrote in message
news:b949b6a7.0410142325.3a379563@posting.google.com...
> 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'Addres
s,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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Accessing Windows environment vairables in ObjectADA on windows
2004-10-15 7:25 Accessing Windows environment vairables in ObjectADA on windows TARAN TRIPATHI
` (4 preceding siblings ...)
2004-10-16 3:09 ` Steve
@ 2004-10-18 20:01 ` Frank Beard
5 siblings, 0 replies; 7+ messages in thread
From: Frank Beard @ 2004-10-18 20:01 UTC (permalink / raw)
To: TARAN TRIPATHI, comp.lang.ada
You could look at Pascal Obry's POSIX Windows package
(http://perso.wanadoo.fr/pascal.obry/archive/w32posix.html).
The link to download it is at the bottom of the page.
It is bascially the POSIX spec wrapped around the
Win32 calls.
Look in
POSIX_Process_Environment.Environment_Value_Of. I've
used it and it works.
Frank
--- TARAN TRIPATHI <tarantripathi@ieee.org> wrote:
> 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.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
>
http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
^ permalink raw reply [flat|nested] 7+ messages in thread