Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetPrivateProfileString and environment variables

Status
Not open for further replies.

dcswee

Programmer
Jan 23, 2002
13
GB
Does anybody know of a way to use windows variables such as %logonserver% in API calls such as GetPrivateProfileString?

Example: I have a string which points to a .INI file, 'server.ini'. Server.ini is stored on a different server depending on which machine you logged onto, but the path is always the same. The string is therefore:

"%logonserver%\res\server.ini"

Why cant I use GetPrivateProfileString like this:

char filename[256];
DWORD result = GetPrivateProfileString(
"Default",
"Resource file name",
"",
filename,
sizeof(filename),
"%logonserver%\res\server.ini);

The only way I can think of is to strip anything between % and % then use getenv() on that part of the string, is there a simpler way that I have missed????

Help would be most appreciated!!!
 
Take a look at:
ExpandEnvironmentStrings

It doesn't work with just any string -- the replacement string must be the name of an enviromental variable.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top