Collapse the table of content
Expand the table of content



Call this member function to write the specified string into the specified section of the application's registry or .INI file.

      BOOL WriteProfileString(
   LPCTSTR lpszSection,
   LPCTSTR lpszEntry,
   LPCTSTR lpszValue 


Points to a null-terminated string that specifies the section containing the entry. If the section does not exist, it is created. The name of the section is case independent; the string may be any combination of uppercase and lowercase letters.


Points to a null-terminated string that contains the entry into which the value is to be written. If the entry does not exist in the specified section, it is created. If this parameter is NULL, the section specified by lpszSection is deleted.


Points to the string to be written. If this parameter is NULL, the entry specified by the lpszEntry parameter is deleted.

Nonzero if successful; otherwise 0.


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.


Header: afxwin.h

© 2016 Microsoft