Environment variables on cross platform

95 views
Skip to first unread message

Kevin Ingwersen (Ingwie Phoenix)

unread,
Dec 1, 2014, 7:18:30 PM12/1/14
to fltkg...@googlegroups.com
Hey

I want to control my FLTK app with a few simple environment variables. However, I don’t know how to get all of them on Windows. I know that getenv and putenv are working on UNIX and Windows. But what about getting all of them? For UNIX, I know this:


extern char** environ;

But…what about Windows? I am talking about native Windows, not cygwin or mingw.

Kind regards,
Ingwie

Greg Ercolano

unread,
Dec 1, 2014, 7:38:39 PM12/1/14
to fltkg...@googlegroups.com
On 12/01/14 16:18, Kevin Ingwersen (Ingwie Phoenix) wrote:
> I know that getenv and putenv are working on UNIX and Windows. But what about getting all of them? [..]
> [how do I get all environment variables, not just one]
> But…what about Windows? I am talking about native Windows, not cygwin or mingw.

You probably want GetEnvironmentStrings.

Google should be your friend here; found in seconds searching for
"C++ windows get all environment variables" which brought me to
this stackoverflow article:
http://stackoverflow.com/questions/9535112/get-all-env-variables-in-c-c-on-windows

Ya, the 3 argument version of main() is probably not something we support
on Windows native, because of how FLTK provides its own WinMain() and calls
only the two argument version of main().

However, I guess I'd be surprised if native windows didn't support
the global "extern char **environ" thing.. try it; if it works, that'd
be a cross platform solution.

MacArthur, Ian (Selex ES, UK)

unread,
Dec 2, 2014, 5:20:55 AM12/2/14
to fltkg...@googlegroups.com
> > I know that getenv and putenv are working on UNIX and Windows. But
> what about getting all of them? [..]
> > [how do I get all environment variables, not just one]
> > But…what about Windows? I am talking about native Windows, not cygwin
> or mingw.
>
> You probably want GetEnvironmentStrings.
>
> Google should be your friend here; found in seconds searching for
> "C++ windows get all environment variables" which brought me to
> this stackoverflow article:
> http://stackoverflow.com/questions/9535112/get-all-env-variables-
> in-c-c-on-windows
>
> Ya, the 3 argument version of main() is probably not something we
> support
> on Windows native, because of how FLTK provides its own WinMain()
> and calls
> only the two argument version of main().
>
> However, I guess I'd be surprised if native windows didn't support
> the global "extern char **environ" thing.. try it; if it works,
> that'd
> be a cross platform solution.


I have a vague recollection that I tried this and it worked, some time ago, but am not sure...

Though to be honest I rarely grab the full environ anyway, I'm usually only interested in the vars I know the names of.



Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************
Reply all
Reply to author
Forward
0 new messages