Partager via


CWinApp::GetProfileInt

Call this member function to retrieve the value of an integer from an entry within a specified section of the application's registry or .INI file.

UINT GetProfileInt(
   LPCTSTR lpszSection,
   LPCTSTR lpszEntry,
   int nDefault 
);

Parameters

  • lpszSection
    Points to a null-terminated string that specifies the section containing the entry.

  • lpszEntry
    Points to a null-terminated string that contains the entry whose value is to be retrieved.

  • nDefault
    Specifies the default value to return if the framework cannot find the entry. This value can be an unsigned value in the range 0 through 65,535 or a signed value in the range –32,768 through 32,767.

Return Value

The integer value of the string that follows the specified entry if the function is successful. The return value is the value of the nDefault parameter if the function does not find the entry. The return value is 0 if the value that corresponds to the specified entry is not an integer.

This member function supports hexadecimal notation for the value in the .INI file. When you retrieve a signed integer, you should cast the value into an int.

Remarks

This member function is not case sensitive, so the strings in the lpszSection and lpszEntry parameters may differ in case.

Security noteSecurity Note

The data returned by this function is not necessarily NULL terminated, and the caller must perform validation. For more information, see Avoiding Buffer Overruns.

Example

CWinApp* pApp = AfxGetApp();

const TCHAR* pszKey = _T("My Section"); 
const TCHAR* pszName = _T("Julian");
int iAge = 26;

// Write the information to the registry.

pApp->WriteProfileString(pszKey, _T("Name"), pszName);
pApp->WriteProfileInt(pszKey, _T("Age"), iAge);

// Read the information from the registry.

CString strName = pApp->GetProfileString(pszKey, _T("Name"));
int iAge2 = pApp->GetProfileInt(pszKey, _T("Age"), 0);

ASSERT(strName == pszName);
ASSERT(iAge2 == iAge);

For an additional example, see CWinApp::WriteProfileInt.

Requirements

Header: afxwin.h

See Also

Reference

CWinApp Class

Hierarchy Chart

CWinApp::GetProfileString

CWinApp::WriteProfileInt

GetPrivateProfileInt

Other Resources

CWinApp Members