Environment variable are variables that can be available to all running programs.  You can access the environment variables using Control Panel > System > Advanced > Environment Variables (Lot of other methods are also available 🙂 )

Environment Variables

Environment Variables

Environment Variables

Environment Variables

In Windows Registry, you can locate them on HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\ Session Manager\ Environment.

Some of the Environment Variables are TEMP, TMP, OS etc.

A number of situations may come during the coding phase to access those variables. For eg: getting the temp folder name, system folder name, lib path, include path etc.

We can access those items from environment variables using the following commands.

ExpandEnvironmentStrings()  – function expands environment-variable strings and replaces them with their defined values.

and ExpandEnvironmentStringsForUser()-function expands the source string by using the environment block established for the specified user.

Like this

CString strErrorMsg = _T(“”);


DWORD dwLen = 0;

dwLen = ::ExpandEnvironmentStrings( _T(“%MSDevDir%”), szEnvPath, MAX_PATH );

if( 0 == dwLen)


// ExpandEnvironmentStrings() failed

strErrorMsg = _T(“Cannot Expand using ExpandEnvironmentStrings()”);


Now the value for the MSDevDir is in the szEnvPath variable. 🙂

for https://vctipsplusplus.wordpress.com/


Every day you waste is one you can never make up