首页 > 解决方案 > 第二次通过循环调用 CButton::Create 时出现运行时检查失败 #0。问题是什么?

问题描述

运行此代码时,我在 Create 的第二次迭代中得到“运行时检查失败 #0”。

    m_nBtnCnt = List.GetCount();
    if (m_pButton = new CColorButton[m_nBtnCnt])
    {
        // create the buttons on the dialog bar
        for (int i = 0; i < m_nBtnCnt; i++)
        {
            // get the button def from the list
            BUTTONDEF Def;
            List.Get(i, (void *)&Def);
            // set up the window rectangle
            CRect Rect(Def.nLeft, Def.nTop + nOff, Def.nLeft + 80, Def.nTop + 50 + nOff);
            // set the window style
            DWORD dwStyle = BS_PUSHBUTTON | BS_MULTILINE | BS_OWNERDRAW | WS_CHILD | WS_VISIBLE;
            // create the button window on the dialog bar
            m_pButton[i].Create(Def.szText, dwStyle, Rect, this, Def.nId);
            m_pButton[i].SetFont(pFont);
            m_pButton[i].SetColor(Def.crButton, Def.crText);
        }
    }

相同的代码存在于三个应用程序中,但我只在一个应用程序中得到错误,然后只有在它以调试模式构建时。代码在视图类的 OnCreate 中;此时不存在其他执行线程。我正在使用带有 MFC 的 VS 2017。如果代码是在发布模式下构建的,则它会毫无错误地执行。我对此感到很困惑;谁能指出我正确的方向?

标签: visual-c++mfc

解决方案


推荐阅读