Access violations
-
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
-
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
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)
-
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)
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
-
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
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