I have this method that initializes a buffer:
void CCreateReportDlg::InitAutoAssignStates()
{
    int iNumColumns = m_Grid.GetColumnCount();
    ASSERT(m_pbyAutoAssignStates == NULL);
    if (m_pbyAutoAssignStates == NULL)
    {
        m_pbyAutoAssignStates = new BYTE[iNumColumns];
        if (m_pbyAutoAssignStates != NULL)
        {
            // This sets them all to AUTO_ASSIGN_INCLUDE
            ZeroMemory(m_pbyAutoAssignStates, iNumColumns * sizeof(BYTE));
            // DATE is never used for auto assign
            m_pbyAutoAssignStates[COLUMN_DATE] = AUTO_ASSIGN_NOT_USED;
        }
    }
}
So far, so good. This buffer gets passed into a dialog class.
// Receives pointer to a BYTE* array.
//     This is owned by the parent.
void CAutoAssignSettingsDlg::SetAutoAssignStates(BYTE *pbyAutoAssignStates)
{
    m_pbyAutoAssignStates = pbyAutoAssignStates;
}
No problems there. I then have a checked list on the dialog that is mapped to each of the states in the above buffer.
When the popup dialog is about to close it revises the buffer:
void CAutoAssignSettingsDlg::UpdateAutoAssignStates()
{
    LVITEM  sItem;
    int     iAssign, iNumAssign;
    if (m_pbyAutoAssignStates != NULL)
    {
        sItem.mask = LVIF_IMAGE|LVIF_PARAM;
        sItem.iSubItem = 0;
        iNumAssign = m_listAssign.GetItemCount();
        for (iAssign = 0; iAssign < iNumAssign; iAssign++)
        {
            sItem.iItem = iAssign;
            m_listAssign.GetItem(&sItem);
            if (sItem.iImage == IMG_CHECKED)
                m_pbyAutoAssignStates[sItem.lParam] = AUTO_ASSIGN_EXCLUDE;
            else
                m_pbyAutoAssignStates[sItem.lParam] = AUTO_ASSIGN_INCLUDE;
        }
    }
}
This all works. But then I want to save it to the registry. At the moment I do it like this:
theApp.WriteProfileBinary(strSection, _T("AssignStates"), m_pbyAutoAssignStates, sizeof(m_pbyAutoAssignStates));
Finally, in the parent dialog, I adjusted the code that reads the settings in from the registry. So now, before the InitAutoAssignStates call I do this:
theApp.GetProfileBinary(strSection,_T("AssignStates"), &ppData, &uSize);
if (uSize > 0)
{
    m_pbyAutoAssignStates = new BYTE[uSize];
    memcpy(m_pbyAutoAssignStates, ppData, uSize);
}
// Tidy memory
if (uSize != 0)
{
    delete[] ppData;
    ppData = NULL;
}
The subsequent InitAutoAssignStates method is only called now if the buffer is NULL. So in theory I shoudlread back in the buffer that I saved. But it is not working. The set of items ticked in my check boxes do not match.
What am I doing wrong?