GetPrivateProfileString

Version 3.0

Syntax

int GetPrivateProfileString(lpApplicationName,lpKeyName,lpDefault,lpReturnedString,nSize,lpFileName)

This function copies a character string from the specified initialization file into the buffer pointed to by the lpReturnedString parameter.

The function searches the file for a key that matches the name specified by the lpKeyName parameter under the application heading specified by the lpApplicationName 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 the initialization file must have the following form:

[application name]

keyname = string

.

.

.

If lpKeyName is NULL, the GetPrivateProfileString function enumerates all key names associated with lpApplicationName 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  

lpApplicationName LPSTR Points to the name of a Windows application that appears in the initialization file.  
lpKeyName LPSTR Points to a key name that appears in the initialization file.  
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.  
Parameter Type/Description  

nSize int Specifies the maximum number of characters (including the last null character) to be copied to the buffer.  
lpFileName LPSTR Points to a string that names the initialization file. If lpFileName does not contain a path to the file, Windows searches for the file in the Windows directory.  

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

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