Version: 3.0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Environment

Detailed Description

These functions allow access to get or change the values of environment variables in a portable way.

They are currently implemented under Win32 and POSIX-like systems (Unix).

Remember that these functions add/change/delete environment variables of the current process only. Child processes copy the environment variables of the parent but do not share them (a wxSetEnv() in the parent process won't change the value returned by wxGetEnv() in the child process and viceversa).

For more evoluted interprocess communication tecniques see Interprocess Communication.

Typedefs

typedef wxStringToStringHashMap wxEnvVariableHashMap
 A map type containing environment variables names and values.
 

Functions

wxCharwxGetenv (const wxString &var)
 This is a macro defined as getenv() or its wide char version in Unicode mode.
 
bool wxGetEnv (const wxString &var, wxString *value)
 Returns the current value of the environment variable var in value.
 
bool wxSetEnv (const wxString &var, const wxString &value)
 Sets the value of the environment variable var (adding it if necessary) to value.
 
bool wxUnsetEnv (const wxString &var)
 Removes the variable var from the environment.
 
bool wxGetEnvMap (wxEnvVariableHashMap *map)
 Fill a map with the complete content of current environment.
 

Typedef Documentation

typedef wxStringToStringHashMap wxEnvVariableHashMap

A map type containing environment variables names and values.

This type is used with wxGetEnvMap() function and wxExecuteEnv structure optionally passed to wxExecute().

Since
2.9.2

Include file:

#include <wx/utils.h> 

Function Documentation

wxChar* wxGetenv ( const wxString var)

This is a macro defined as getenv() or its wide char version in Unicode mode.

Note that under Win32 it may not return correct value for the variables set with wxSetEnv(), use wxGetEnv() function instead.

Include file:

#include <wx/utils.h> 
bool wxGetEnv ( const wxString var,
wxString value 
)

Returns the current value of the environment variable var in value.

value may be NULL if you just want to know if the variable exists and are not interested in its value.

Returns true if the variable exists, false otherwise.

Include file:

#include <wx/utils.h> 
bool wxGetEnvMap ( wxEnvVariableHashMap map)

Fill a map with the complete content of current environment.

The map will contain the environment variable names as keys and their values as values.

Parameters
mapThe environment map to fill, must be non-NULL.
Returns
true if environment was successfully retrieved or false otherwise.

Include file:

#include <wx/utils.h> 
Since
2.9.2
bool wxSetEnv ( const wxString var,
const wxString value 
)

Sets the value of the environment variable var (adding it if necessary) to value.

Notice that under Windows platforms the program may have two different environment blocks: the first one is that of a Windows process and is always present, but the CRT may maintain its own independent copy of the environment. wxSetEnv() will always update the first copy, which means that wxGetEnv(), which uses it directly, will always return the expected value after this call. But wxSetEnv() only updates the second copy for some compilers/CRT implementations (currently only MSVC and MinGW which uses the same MSVC CRT) and so using wxGetenv() (notice the difference in case) may not return the updated value.

Parameters
varThe environment variable to be set, must not contain '=' character.
valueNew value of the variable.
Returns
true on success or false if changing the value failed.
See Also
wxUnsetEnv()

Include file:

#include <wx/utils.h> 
bool wxUnsetEnv ( const wxString var)

Removes the variable var from the environment.

wxGetEnv() will return NULL after the call to this function.

Returns true on success.

Include file:

#include <wx/utils.h>