exceptionvisual-c++mfclistctrl

lstrcpy() causing exceptions in visual C++ code


I used a MFC virtual list control to enhance the performance and I handle GetDispInfo(NMHDR* pNMHDR, LRESULT* pResult) to populate the ListCtrl. The relevant code in that method is as follows:

if (pItem->mask && LVIF_TEXT) {

    switch(pItem->iSubItem)

    {
        case 0:
            lstrcpy(pItem->pszText, rLabel.m_strText);  
        break;
        case 1:
            sprintf(pItem->pszText, "%d", p.o_Value);
        break;
        default:
            ASSERT(0);
        break;
    }
}

Here, when I use lstrcpy(),when I'm srolling down/up, I get a whole lot of exceptions saying First-chance exception at 0x7c80c741 in test_list_control.exe: 0xC0000005: Access violation writing location 0xb70bf2ac. These messages appear in the debug output. But the program doesn't crash. Can anyone please explain what the matter here and how should I overcome that??

rLabel is a CLabelItem which I have declared earlier.

Thank you!


Solution

  • If all you see is the first chance exception thing, stop worrying. See for example Link but you can find similar pages all over the place (mostly from 5-10 years ago.) It means some code threw and the exception was caught and dealt with. I see this in MFC apps some times. As the blog entry says

    First chance exception messages most often do not mean there is a problem in the code.

    I would wait until you see actual errors before getting worked up about this one.