Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

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  
);
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.

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.

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

Security note Security 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.

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.

Header: afxwin.h

Show:
© 2014 Microsoft. All rights reserved.