16.3. Getting and Setting Environment Strings
Environment variables often contain information that is useful during the execution of a program. For example, you might want to retrieve the current path so that you can search it for a specific directory name. To retrieve environment variables, use theExpandEnvironmentString function, as shown in Listing 16.3.
Code Listing 16.3. Using the ExpandEnvironmentString function
// siees.cpp #include <windows.h> #include <iostream.h> void main() { char s[1000]; DWORD result; result = ExpandEnvironmentStrings("%path%", s, 1000); if (result == 0) { cout << "Error: " << GetLastError() << endl; return; } cout << s << endl; } |
The function accepts a string containing one or more environment variable names ...
Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.