Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

CWinApp::GetProfileBinary

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  
);
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 value is to be retrieved.

ppData

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

pBytes

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, 
   sizeof(myData));

// Read the information from the registry.

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

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.