ExpandEnvironmentStrings

The ExpandEnvironmentStrings function expands environment-variable strings and replaces them with their defined values.

DWORD ExpandEnvironmentStrings(
  LPCTSTR lpSrc, // pointer to string with environment variables
  LPTSTR lpDst,  // pointer to string with expanded environment 
                 // variables
  DWORD nSize    // maximum characters in expanded string
);
 

Parameters

lpSrc
Pointer to a null-terminated string that might contain references to environment-variable strings of the form:
%variableName% 
 

For each such reference, the %variableName% portion is replaced with the current value of that environment variable.

The replacement rules are the same as those used by the command interpreter. Case is ignored when looking up the environment-variable name. If the name is not found, the %variableName% portion is left undisturbed.

lpDst
Pointer to a buffer to receive a copy of the source buffer, after all environment-variable name substitutions have been performed.
nSize
Specifies the maximum number of characters that can be stored in the buffer pointed to by the lpDst parameter, including the terminating null character.

Return Values

If the function succeeds, the return value is the number of bytes (ANSI version) or characters (Unicode version) stored in the destination buffer, including the terminating null character. If the destination buffer is too small to hold the expanded string, the return value is the required buffer size, in bytes or characters.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

System Information Overview, System Information Functions