Export (0) Print
Expand All
Expand Minimize


Call this member function to retrieve binary data from an entry within a specified section of the application's registry or .INI file.

BOOL GetProfileBinary( 
   LPCTSTR lpszSection, 
   LPCTSTR lpszEntry, 
   LPBYTE* ppData, 
   UINT* pBytes  


Points to a null-terminated string that specifies the section containing the entry.


Points to a null-terminated string that contains the entry whose value is to be retrieved.


Points to a pointer that will receive the address of the data.


Points to a UINT that will receive the size of the data (in bytes).

Nonzero if successful; otherwise 0.

This member function is not case sensitive, so the strings in the lpszSection and lpszEntry parameters may differ in case.

Note Note

GetProfileBinary allocates a buffer and returns its address in *ppData. The caller is responsible for freeing the buffer using delete [].

Security note Security 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.

CWinApp* pApp = AfxGetApp();

const TCHAR* pszKey = _T("My Section");
struct complex {
  double re, im;
} myData = { 1.4142, -0.5 };

// Write the information to the registry.

pApp->WriteProfileBinary(pszKey, _T("ComplexData"), (LPBYTE)&myData, 

// Read the information from the registry.

complex* pData;
BOOL ret = pApp->GetProfileBinary(pszKey, _T("ComplexData"), (LPBYTE*)&pData, 

ASSERT(n == sizeof(complex));
ASSERT(myData.re == pData->re);
ASSERT(myData.im == pData->im);
delete [] pData; // free the buffer

For an additional example, see CWinApp::WriteProfileBinary.

Header: afxwin.h

© 2015 Microsoft