共用方式為


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

Parameters

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

Return Value

Nonzero if successful; otherwise 0.

Remarks

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

注意

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

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

Example

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.

Smart Device Developer Notes

Only the registry-based version using CWinApp::SetRegistryKey is supported in Windows CE-based projects.

Requirements

Header: afxwin.h

See Also

Concepts

CWinApp Class

CWinApp Members

Hierarchy Chart

CWinApp::GetProfileInt

CWinApp::GetProfileString