MFC - CList RemoveAt() function

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

MFC - CList RemoveAt() function

 
0
  #1
May 4th, 2006
Hello guys i keep getting a

Unhandled exception at 0x7c177ac0 (mfc71d.dll) in LSMUtility.exe: 0xC0000005: Access violation reading location 0xcdcdcdbd.
However according to MSDN the code is right:

  1. void CTemp::OnDelete()
  2. {
  3. // TODO: Add your control notification handler code here
  4. CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
  5.  
  6. if(pos != main_dlg->BTList.GetTailPosition())
  7. {
  8. main_dlg->BTList.RemoveAt(pos);
  9. MessageBox("deleted");
  10. }
  11. }

the above code works and the error only occurs if itterate through the list by using Next and Back buttons and functions:

  1. void CTemp::OnNext()
  2. {
  3. // TODO: Add your control notification handler code here
  4. CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
  5. if(pos != main_dlg->BTList.GetTailPosition())
  6. {
  7. main_dlg->BTList.GetNext(pos);
  8. Display();
  9. }
  10. else
  11. MessageBox("end");
  12. }
  13.  
  14. //and Pervious
  15.  
  16. void CTemp::OnPervious()
  17. {
  18. // TODO: Add your control notification handler code here
  19. CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
  20. if(pos != main_dlg->BTList.GetHeadPosition())
  21. {
  22. main_dlg->BTList.GetPrev(pos);
  23. Display();
  24. }
  25. else
  26.  
  27. MessageBox("At beginning");
  28. }
Can anyone suggest where i've gone wrong please?

Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,443
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: MFC - CList RemoveAt() function

 
0
  #2
May 4th, 2006
Access violation reading location 0xcdcdcdbd.
Isn't that how uninitialized memory is filled in debug mode?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: MFC - CList RemoveAt() function

 
0
  #3
May 4th, 2006
Originally Posted by Dave Sinkula
Access violation reading location 0xcdcdcdbd.
Isn't that how uninitialized memory is filled in debug mode?
I think so, but I'm not sure how to fix it, it would appear that when i delete an object from the list, it gets deleted, but if i click pervious that works but then if i delete that and click 'next' i get that error.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC