GetProfileString

Syntax

int GetProfileString(lpAppName,lpKeyName,lpDefault,lpReturnedString,nSize)

This function copies a character string from the Windows initialization file, WIN.INI, into the buffer pointed to by the lpReturnedString parameter. The function searches WIN.INI for a key that matches the name specified by the lpKeyName parameter under the application heading specified by the lpAppName parameter. If the key is found, the corresponding string is copied to the buffer. If the key does not exist, the default character string specified by the lpDefault parameter is copied. A string entry in WIN.INI must have the following form:

[application name]

keyname = value

.

.

.

If lpKeyName is NULL, the GetProfileString function enumerates all key names associated with lpAppName by filling the location pointed to by lpReturnedString with a list of key names (not values). Each key name in the list is terminated with a null character.

Parameter Type/Description  

lpAppName LPSTR Points to a null-terminated character string that names the application.  
lpKeyName LPSTR Points to a null-terminated character string that names a key.  
lpDefault LPSTR Specifies the default value for the given key if the key cannot be found in the initialization file.  
lpReturnedString LPSTR Points to the buffer that receives the character string.  
nSize int Specifies the number of characters (including the last null character) that will be copied to the buffer.  

Return Value

The return value specifies the number of characters copied to the buffer identified by the lpReturnedString parameter, not including the terminating null character. If the buffer is not large enough to contain the entire string and lpKeyName is not NULL, the return value is equal to the length specified by the nSize parameter. If the buffer is not large enough to contain the entire string and lpKeyName is NULL, the return value is equal to the length specified by the nSize parameter minus 2.

Comments

GetProfileString is not case-dependent, so the strings in lpAppName and lpKeyName may be in any combination of uppercase and lowercase letters.