Share via


CWinApp::WriteProfileBinary

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

BOOL WriteProfileBinary(
   LPCTSTR lpszSection,
   LPCTSTR lpszEntry,
   LPBYTE pData,
   UINT nBytes 
);

Parameters

  • lpszSection
    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.

  • lpszEntry
    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.

  • pData
    Points to the data to be written.

  • nBytes
    Contains the number of bytes to be written.

Return Value

Nonzero if successful; otherwise 0.

Example

This example uses CWinApp* pApp = AfxGetApp(); to get at the CWinApp class illustrating a way that WriteProfileBinary and GetProfileBinary can be used from any function in an MFC application.

CWinApp* pApp = AfxGetApp();

CString strSection = _T("My Section");
CString strItem = _T("My Binary Item");
double myData = 123.456e12;

pApp->WriteProfileBinary(strSection, strItem, (LPBYTE)&myData, sizeof(myData));
double *pData;
UINT n;
pApp->GetProfileBinary(strSection, strItem, (LPBYTE*)&pData, &n);
ASSERT(n == sizeof(myData));
ASSERT(myData = *pData);
delete [] pData;  // free the buffer

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

Requirements

Header: afxwin.h

See Also

Reference

CWinApp Class

Hierarchy Chart

CWinApp::WriteProfileInt

CWinApp::WriteProfileString

CWinApp::SetRegistryKey

Other Resources

CWinApp Members