views:

31

answers:

2

Hi,

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!

+1  A: 

I think you should check if buffer that is pointed by pItem->pszText is large enough to hold rLabel.m_strText. Or if rLabel.m_strText is correct null terminated string. For me this looks like writing uninitialized memory. Use the debugger to check this.

Zuljin
+1  A: 

If all you see is the first chance exception thing, stop worrying. See for example http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx 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.

Kate Gregory