Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Access Violation During adding items in List Control ( CXListCtrl )....

Access Violation During adding items in List Control ( CXListCtrl )....

Scheduled Pinned Locked Moved C / C++ / MFC
c++announcementcomgraphicsdebugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ravi Sankar S
    wrote on last edited by
    #1

    Hello All, I am developing a sample SDI application in VC++ 6.0 on Windows 2000 Professional. My view class is derived from "CFormView". I am using this List control taken from http://www.codeproject.com/listctrl/xlistctrl.asp on my Form. Creation and initial display are proper and when i try to add an Item it gives access violation. Here is the code used to update the List control. BOOL CMyView::UpdateList (int l_iRow, CInfo *l_oInfo) { CString l_strTemp; int l_iRowCount = 0; // ID l_strTemp.Format ("%d", l_oInfo->m_lID); if (l_iRow == -1) { // add at the end of the list l_iRow = m_oTabList.GetItemCount (); m_oTabList.InsertItem(l_iRow, l_strTemp, RGB(255, 0, 0), RGB(255, 255, 255)); } else { l_iRow--; m_oTabList.SetItemText (l_iRow, l_iRowCount, l_strTemp); } l_iRowCount++; .... If I debug and see the above function is executing fine. but it fails while drawing the items in Line Number 842 of XListCtrl.cpp in Function "DrawText m_HeaderCtrl.GetItem(nSubItem, &hditem); In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation _AFXCMN_INLINE BOOL CHeaderCtrl::GetItem(int nPos, HDITEM* pHeaderItem) const { ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nPos, (LPARAM)pHeaderItem); } Since ASSERT won't execute in Release mode it is working fine in Release mode. The code used to insert column is below m_oList.SetExtendedStyle(m_oList.GetStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); // Insert the columns for the list control m_oList.InsertColumn (0, _T("ID"), LVCFMT_CENTER, 40); m_oList.InsertColumn (1, _T("No"), LVCFMT_CENTER, 80); m_oList.InsertColumn (2, _T("Time"), LVCFMT_CENTER, 120); After this code I am inserting new items. Can any one suggest what may be the problem. Thanks in Advance Ravi

    R 1 Reply Last reply
    0
    • R Ravi Sankar S

      Hello All, I am developing a sample SDI application in VC++ 6.0 on Windows 2000 Professional. My view class is derived from "CFormView". I am using this List control taken from http://www.codeproject.com/listctrl/xlistctrl.asp on my Form. Creation and initial display are proper and when i try to add an Item it gives access violation. Here is the code used to update the List control. BOOL CMyView::UpdateList (int l_iRow, CInfo *l_oInfo) { CString l_strTemp; int l_iRowCount = 0; // ID l_strTemp.Format ("%d", l_oInfo->m_lID); if (l_iRow == -1) { // add at the end of the list l_iRow = m_oTabList.GetItemCount (); m_oTabList.InsertItem(l_iRow, l_strTemp, RGB(255, 0, 0), RGB(255, 255, 255)); } else { l_iRow--; m_oTabList.SetItemText (l_iRow, l_iRowCount, l_strTemp); } l_iRowCount++; .... If I debug and see the above function is executing fine. but it fails while drawing the items in Line Number 842 of XListCtrl.cpp in Function "DrawText m_HeaderCtrl.GetItem(nSubItem, &hditem); In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation _AFXCMN_INLINE BOOL CHeaderCtrl::GetItem(int nPos, HDITEM* pHeaderItem) const { ASSERT(::IsWindow(m_hWnd)); return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nPos, (LPARAM)pHeaderItem); } Since ASSERT won't execute in Release mode it is working fine in Release mode. The code used to insert column is below m_oList.SetExtendedStyle(m_oList.GetStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); // Insert the columns for the list control m_oList.InsertColumn (0, _T("ID"), LVCFMT_CENTER, 40); m_oList.InsertColumn (1, _T("No"), LVCFMT_CENTER, 80); m_oList.InsertColumn (2, _T("Time"), LVCFMT_CENTER, 120); After this code I am inserting new items. Can any one suggest what may be the problem. Thanks in Advance Ravi

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      Ravi Sankar S wrote: m_HeaderCtrl.GetItem(nSubItem, &hditem); In the GetItem the m_hWnd is NULL so code in AFXCMN.INL gives Access Violation Check how m_HeaderCtrl is initialized. The m_hWnd in GetItem is the one from m_HeaderCtrl, which does seem to be an initialized object in your case. Ravi Sankar S wrote: Since ASSERT won't execute in Release mode it is working fine in Release mode. I would not rely on such a statement. If it fails in Debug, it does not work either in Release, it is only that the problem does not assert immediately (the effects of what goes wrong does not show immediately). But it can bring unexpected (and sometimes unrelated) errors later for the program user :~ ... So better be sure to find what goes wrong. ~RaGE();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups