开发者

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 e开发者_StackOverflowxplain what the matter here and how should I overcome that??

rLabel is a CLabelItem which I have declared earlier.

Thank you!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜