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.

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.

The entries are stored as follows:

  • In Windows NT, the value is stored to a registry key.

  • In Windows 3.x, the value is stored in the WIN.INI file.

  • In Windows 95/98, the value is stored in a cached version of WIN.INI.

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.

BOOL CMyApp::InitInstance()
{
    // CMyApp is derived from CWinApp.

    const char *pszKey = "MyApp";
    const char *pszName = "Julian";
    int iAge = 26;

    // Change the registry key under which our settings are stored.

    SetRegistryKey(_T(""));

    // Write the information to the registry.

    WriteProfileString(pszKey, "Name", pszName);
    WriteProfileInt(pszKey, "Age", iAge);

    // Read the information from the registry.

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

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

    return TRUE;
}

For an additional example, see CWinApp::WriteProfileInt.

Only the registry-based version using CWinApp::SetRegistryKey is supported in Windows CE-based projects.

Community Additions

ADD
Show: