comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey D. Cherry" <jdcherry@utech.net>
To: Al Lively <al.lively@business.gatech.edu>
Subject: Re: Dos Environment varables
Date: 1999/05/24
Date: 1999-05-24T00:00:00+00:00	[thread overview]
Message-ID: <37497064.C4457F71@utech.net> (raw)
In-Reply-To: 7i42q7$c48$1@news-int.gatech.edu

Al,

The GNAT OS_Lib route is a great way to get environment variables when
you want to port your application accross different platforms.  If you
are going to stay with Windows, then using the Win32 API is a good
"portability" alternative, again the condition being that you stay
within the Windows family (95/98/NT).  Here is a function that I've used
with the OA compiler.  I've used it on Windows 95, 98, and NT without
any problems.  Hope it helps.

Regard,
Jeffrey D. Cherry
Logicon Geodynamics

-----
with Ada.Strings.Unbounded;

function Get_Environment_Variable(Name : in string)
      return Ada.Strings.Unbounded.Unbounded_String;
-----
with Win32;
with Win32.Winbase;

with Ada.Characters.Latin_1;

function Get_Environment_Variable(Name : in string) 
      return Ada.Strings.Unbounded.Unbounded_String is
   
   N : string(1 .. Name'length+1) := Name & Ada.Characters.Latin_1.Nul;
   B : string(1 .. 2048);
   S : Win32.DWORD;
         
begin -- Get_Environment_Variable
   S := Win32.Winbase.GetEnvironmentVariable(Win32.Addr(N),
Win32.Addr(B),
         Win32.DWORD(B'length));
   if (integer(S) <= 0) then
      return Ada.Strings.Unbounded.Null_Unbounded_String;
   else
      return
Ada.Strings.Unbounded.To_Unbounded_String(B(1..positive(S)));
   end if;            
end Get_Environment_Variable;
-----




  parent reply	other threads:[~1999-05-24  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-21  0:00 Dos Environment varables Al Lively
1999-05-21  0:00 ` Keith Thompson
1999-05-21  0:00 ` Gautier
1999-05-21  0:00   ` Al Lively
1999-05-21  0:00     ` Gautier
1999-05-24  0:00     ` Jeffrey D. Cherry [this message]
1999-05-25  0:00       ` Pascal Obry
1999-05-25  0:00         ` Jeffrey D. Cherry
1999-05-22  0:00 ` David Botton
replies disabled

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