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 violations

Access violations

Scheduled Pinned Locked Moved C / C++ / MFC
designquestionannouncement
4 Posts 3 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.
  • P Offline
    P Offline
    packetlos
    wrote on last edited by
    #1

    Hi, I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:

    LRESULT CNetworkMonitoringListView::OnThreadUpdate(WPARAM wParam, LPARAM lParam)
    {
    CString sResult;
    LV_ITEM lvi;
    
    lvi.mask = LVIF_TEXT | LVIF_DI_SETITEM;	// instance mask
    lvi.iItem = (INT)lParam;		// position in control
    lvi.iSubItem = 0;			// column
    lvi.pszText = (LPTSTR)(LPCTSTR)lParam;	// 
    GetListCtrl().InsertItem(&lvi);		// insert the item
    
    for (int i = 0; i < 5; i++)
    {
    	lvi.iSubItem = i;
    	GetDocument()->m_cs.Lock();
    	// get the text for the relevant row subitem
    	sResult = GetDocument()->m_capturedPacket.GetDescription((UINT)lParam, i);
    	GetDocument()->m_cs.Unlock();
    	lvi.pszText = (LPTSTR)(LPCTSTR)(sResult);
    	GetListCtrl().SetItem(&lvi);
    		
    	}
    
    return 0;
    }
    

    The second time the message from the worker thread is processed

    GetListCtrl().InsertItem(&lvi)
    

    causes an access violation and fails to add another entry into the CListview, is there anything I can do? :(( Cheers Packetlos

    D 1 Reply Last reply
    0
    • P packetlos

      Hi, I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:

      LRESULT CNetworkMonitoringListView::OnThreadUpdate(WPARAM wParam, LPARAM lParam)
      {
      CString sResult;
      LV_ITEM lvi;
      
      lvi.mask = LVIF_TEXT | LVIF_DI_SETITEM;	// instance mask
      lvi.iItem = (INT)lParam;		// position in control
      lvi.iSubItem = 0;			// column
      lvi.pszText = (LPTSTR)(LPCTSTR)lParam;	// 
      GetListCtrl().InsertItem(&lvi);		// insert the item
      
      for (int i = 0; i < 5; i++)
      {
      	lvi.iSubItem = i;
      	GetDocument()->m_cs.Lock();
      	// get the text for the relevant row subitem
      	sResult = GetDocument()->m_capturedPacket.GetDescription((UINT)lParam, i);
      	GetDocument()->m_cs.Unlock();
      	lvi.pszText = (LPTSTR)(LPCTSTR)(sResult);
      	GetListCtrl().SetItem(&lvi);
      		
      	}
      
      return 0;
      }
      

      The second time the message from the worker thread is processed

      GetListCtrl().InsertItem(&lvi)
      

      causes an access violation and fails to add another entry into the CListview, is there anything I can do? :(( Cheers Packetlos

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      packetlos wrote: I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view: Use PostMessage() instead. Read this article.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      P 1 Reply Last reply
      0
      • D David Crow

        packetlos wrote: I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view: Use PostMessage() instead. Read this article.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        P Offline
        P Offline
        packetlos
        wrote on last edited by
        #3

        Cheers for the link, i have read the article and I am doing what it suggests by using a user defined message to trigger OnThreadUpdate now using PostMessage() and it is still causing access violations. Any other things I should be looking at anybody? Thanks

        N 1 Reply Last reply
        0
        • P packetlos

          Cheers for the link, i have read the article and I am doing what it suggests by using a user defined message to trigger OnThreadUpdate now using PostMessage() and it is still causing access violations. Any other things I should be looking at anybody? Thanks

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          The VC Debugger will point you towards the location of the access violation, which should help you to fix the cause. Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com

          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