UINT GetPrivateProfileInt(lpszSection, lpszEntry, default, lpszFilename) | |||||
LPCSTR lpszSection; | /* address of section | */ | |||
LPCSTR lpszEntry; | /* address of entry | */ | |||
int default; | /* return value if entry not found | */ | |||
LPCSTR lpszFilename; | /* address of initialization filename | */ |
The GetPrivateProfileInt function retrieves the value of an integer from an entry within a specified section of a specified initialization file.
lpszSection
Points to a null-terminated string containing the section heading in the initialization file.
lpszEntry
Points to the null-terminated string containing the entry whose value is to be retrieved.
default
Specifies the default value to return if the entry cannot be found in the initialization file. This value must be a positive integer in the range 0 through 32,767 (0x0000 through 0x7FFF).
lpszFilename
Points to a null-terminated string that names the initialization file. If this parameter does not contain a full path, Windows searches for the file in the Windows directory.
The return value is the integer value of the specified entry if the function is successful. It is the value of the default parameter if the function does not find the entry. The return value is zero if the value that corresponds to the specified entry is not an integer.
The function searches the file for an entry that matches the name specified by the lpszEntry parameter under the section heading specified by the lpszSection parameter. An integer entry in the initialization file must have the following form:
[section]
entry=value
.
.
.
If the value that corresponds to the entry consists of digits followed by nonnumeric characters, the function returns the value of the digits. For example, the function would return 102 for the line “Entry=102abc”.
The GetPrivateProfileInt function is not case-dependent, so the strings in the lpszSection and lpszEntry parameters may contain a combination of uppercase and lowercase letters.
GetPrivateProfileInt supports hexadecimal notation. When GetPrivateProfileInt is used to retrieve a negative integer, the value should be cast to an int.
An application can use the GetProfileInt function to retrieve an integer value from the WIN.INI file.
The following example uses the GetPrivateProfileInt function to retrieve the last line number by reading the LastLine entry from the [MyApp] section of TESTCODE.INI:
WORD wInt;
char szMsg[144];
wInt = GetPrivateProfileInt("MyApp", "LastLine",
0, "testcode.ini");
sprintf(szMsg, "last line was %d", wInt);
MessageBox(hwnd, szMsg, "GetPrivateProfileInt", MB_OK);