虚拟列表控制问题
我正在使用虚拟照明控件,并从地图获取数据。我的问题是,当我运行代码时,它显示列表正常,但是当鼠标光标移动到列表控件上或当我尝试向下滚动时,它会给出调试断言失败,指出映射/设置迭代器不可取消引用。我的 GetDispInfo() 方法如下:
void CListCtrlTestDlg::GetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem = &(pDispInfo)->item;
map<int, Error_Struct>::iterator it = Error_Map.find((pItem->iItem) + 1);
int iErrCode = (*it).second.i_ErrorCode;
CString cError = (*it).second.c_Error;
switch(pItem->iSubItem)
{
case 0:
sprintf_s(pItem->pszText, 10, "[ %d ]", iErrCode);
break;
case 1:
sprintf_s(pItem->pszText, 100, "%s", cError);
break;
}
*pResult = 0;
}
另外,如果当鼠标指针位于列表控件的顶部时,程序再次崩溃,并显示 output.c 文件中下面显示的行中的访问冲突:
#else /* _UNICODE */
if (_putc_nolock(ch, f) == EOF)
有人有相同的经历吗?我在这里做错了什么以及如何解决这个问题?
谢谢你!
I'm using a virtual lit control and I get the data from a map. My problem is when I run the code, it displays the list ok, but when the mouse cursor moves on to the list control or when I try to scroll down, it gives a Debug Assertion failure saying map/set iterator is not dereferencable. My GetDispInfo() method is as follows:
void CListCtrlTestDlg::GetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem = &(pDispInfo)->item;
map<int, Error_Struct>::iterator it = Error_Map.find((pItem->iItem) + 1);
int iErrCode = (*it).second.i_ErrorCode;
CString cError = (*it).second.c_Error;
switch(pItem->iSubItem)
{
case 0:
sprintf_s(pItem->pszText, 10, "[ %d ]", iErrCode);
break;
case 1:
sprintf_s(pItem->pszText, 100, "%s", cError);
break;
}
*pResult = 0;
}
Also if when the mouse pointer is on top of the list control, again the program crashes saying access violation from the line showed below in output.c file:
#else /* _UNICODE */
if (_putc_nolock(ch, f) == EOF)
Has anyone got the same experience? What am I doing wrong here and how can I fix this problem?
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于初学者来说,您如何知道传递给 sprintf_s 的神奇常量 10 和 100 实际上是 pItem->pszText 中正确的空间量?您应该使用 pItem->cchText。
其次,您可能应该检查从 std::map::find 返回的迭代器是否有效。
For starters, how do you know that your magic constants 10 and 100, that you're passing to sprintf_s are actually the correct amount of space in pItem->pszText? You should use pItem->cchText.
Second, you should probably check that the iterator returned from std::map::find is valid.
实际问题是我试图将数据复制到 LV_ITEM 结构的非缓冲区成员。我试图将数据复制到一个纯粹的指针,这就是问题所在。我真正应该做的是为该指针分配一个值而不复制数据。
这非常有效!感谢您的帮助。
The actual problem was that I was trying copy data to a non-buffer member of LV_ITEM structure. I was trying to copy data to a mere pointer, that was the problem. What I should have really done was to assign a value to that pointer without copying data.
This works perfectly! Thanks for the help.