Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CWinApp::GetProfileBinary

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

Nonzero if successful; otherwise 0.

The entries are stored as follows:

  • In Windows NT, the value is stored to a registry key.

  • In Windows 3.x, the value is stored in the WIN.INI file.

  • In Windows 95/98, the value is stored in a cached version of WIN.INI.

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

NoteNote

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.

BOOL CMyApp::InitInstance()
{
    // CMyApp is derived from CWinApp.

    const char *pszKey = "MyApp";
    struct complex {
        double re, im;
    } myData = { 1.4142, -0.5 };

    // Change the registry key under which our settings are stored.

    SetRegistryKey(_T(""));

    // Write the information to the registry.

    WriteProfileBinary(pszKey, "ComplexData", (LPBYTE)&myData, sizeof(myData) );

    // Read the information from the registry.

    complex* pData;
    UINT n;
    BOOL ret = GetProfileBinary(pszKey, "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
    return TRUE;
}

For an additional example, see CWinApp::WriteProfileBinary.

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

Community Additions

ADD
Show:
© 2015 Microsoft