Condividi tramite


CWinApp::GetProfileString

Call this member function to retrieve the string associated with an entry within the specified section in the application's registry or .INI file.

CString GetProfileString(
   LPCTSTR lpszSection,
   LPCTSTR lpszEntry,
   LPCTSTR lpszDefault = NULL 
);

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 string is to be retrieved. This value must not be NULL.

  • lpszDefault
    Points to the default string value for the given entry if the entry cannot be found in the initialization file.

Return Value

The return value is the string from the application's .INI file or lpszDefault if the string cannot be found. The maximum string length supported by the framework is _MAX_PATH. If lpszDefault is NULL, the return value is an empty string.

Remarks

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

CString strSection       = _T("My Section");
CString strStringItem    = _T("My String Item");
CString strIntItem       = _T("My Int Item");

pApp->WriteProfileString(strSection, strStringItem, _T("test"));

CString strValue;
strValue = pApp->GetProfileString(strSection, strStringItem);
ASSERT(strValue == _T("test"));

pApp->WriteProfileInt(strSection, strIntItem, 1234);

int nValue;
nValue = pApp->GetProfileInt(strSection, strIntItem, 0);
ASSERT(nValue == 1234);

For another example, see the example for CWinApp::GetProfileInt.

Requirements

Header: afxwin.h

See Also

Reference

CWinApp Class

Hierarchy Chart

CWinApp::GetProfileInt

CWinApp::WriteProfileString

GetPrivateProfileString

Other Resources

CWinApp Members