The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.



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 


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.


Points to the data to be written.


Contains the number of bytes to be written.

Nonzero if successful; otherwise 0.


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


Header: afxwin.h