windows_programming_notes.nbk: Home | Index | Next Page: ExtCreatePen | Previous Page: Examining a Message Queue
ExpandEnvironmentStrings
Expands environment-variable strings and replaces them with the values defined for the current user.
To specify the environment block for a particular user or the system, use the ExpandEnvironmentStringsForUser function.
Syntax
DWORD WINAPI ExpandEnvironmentStrings(
__in LPCTSTR lpSrc,
__out_opt LPTSTR lpDst,
__in DWORD nSize
);
Parameters
- lpSrc
A buffer that contains one or more environment-variable strings in the
form: %variableName%. For each such reference, the %variableName%
portion is replaced with the current value of that environment
variable.
Case is ignored when looking up the environment-variable name. If the
name is not found, the %variableName% portion is left unexpanded.
Note that this function does not support all the features that Cmd.exe
supports. For example, it does not support %variableName:str1=str2% or
%variableName:~offset,length%.
lpDst
A pointer to a buffer that receives the result of expanding the environment variable strings in the lpSrc buffer. Note that this buffer cannot be the same as the lpSrc buffer.
nSize
The maximum number of characters that can be stored in the buffer pointed to by the lpDst parameter. When using ANSI strings, the buffer size should be the string length, plus terminating null character, plus one. When using Unicode strings, the buffer size should be the string length plus the terminating null character.
Return Value
If the function succeeds, the return value is the number of TCHARs 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 characters.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The size of the lpSrc and lpDst buffers is limited to 32K.
To replace folder names in a fully-qualified path with their associated environment-variable strings, use the PathUnExpandEnvStrings function.
To retrieve the list of environment variables for a process, use the GetEnvironmentStrings function.
Requirements
- Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
- Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
- Header Declared in Winbase.h; include Windows.h.
- Library Use Kernel32.lib.
- DLL Requires Kernel32.dll.
- Unicode Implemented as ExpandEnvironmentStringsW (Unicode) and ExpandEnvironmentStringsA (ANSI).
windows_programming_notes.nbk: Home | Index | Next Page: ExtCreatePen | Previous Page: Examining a Message Queue
Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time