0
votes

In my CDialogEx class, I am trying to insert a CMFCRibbonBar, but I get a NULL pointer exception (which is not caught by my try/catch blocks):

BOOL CmfcRibbonTestDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // TODO: Add extra initialization here
    try
    {
        m_wndRibbonBar.Create(this);
        m_wndRibbonBar.LoadFromResource(IDR_RIBBON1);
    }
    catch( std::exception& exc )
    {
        this->MessageBoxA(exc.what(), "Couldn't create ribbon");
    }

    return TRUE;  // return TRUE  unless you set the focus to a control
}

The exact exception says: "Unhandled exception at 0x00d191db in mfcRibbonTest.exe: 0xC0000005: Access violation reading location 0x00000000" and breaks in afxribbonbar.cpp:964.

I did a number of searches to see if a CMFCRibbonBar can be placed in a dialog, but my searches were inconclusive.

1

1 Answers

0
votes

If you look at afxribbonbar.cpp, line 964 you will see this:

LRESULT CMFCRibbonBar::OnPostRecalcLayout(WPARAM,LPARAM)
{
    GetParentFrame()->RecalcLayout();
    return 0;
}

This should give you a hint at what the problem is: GetParentFrame() is returning NULL. By looking at the documentation at http://msdn.microsoft.com/en-us/library/6f45sskz(v=vs.100).aspx we see: "The member function searches up the parent chain until a CFrameWnd (or derived class) object is found."

In your case, there isn't any CFrameWnd, so that's the problem. The bottom line is that ribbon bars aren't designed to be added to dialogs. That doesn't mean it's impossible to do, but at the very least it's going to be an involved process.