954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MFC - CList RemoveAt() function

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:

void CTemp::OnDelete()
{
	// TODO: Add your control notification handler code here
	CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
	
	if(pos != main_dlg->BTList.GetTailPosition())
	{
		main_dlg->BTList.RemoveAt(pos);
		MessageBox("deleted");
	}
}


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

void  CTemp::OnNext()
{
	// TODO: Add your control notification handler code here
		CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
		if(pos != main_dlg->BTList.GetTailPosition())
	{
		 main_dlg->BTList.GetNext(pos);
		Display();
	}
	else
		MessageBox("end");
}

//and Pervious

void CTemp::OnPervious()
{
	// TODO: Add your control notification handler code here
	CLSMUtilityDlg *main_dlg = (CLSMUtilityDlg *) GetParent();
	if(pos != main_dlg->BTList.GetHeadPosition())
	{
		 main_dlg->BTList.GetPrev(pos);
		Display();
	}
	else

		MessageBox("At beginning");
}

Can anyone suggest where i've gone wrong please?

Thanks

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 
Access violation reading location 0xcdcdcdbd.


Isn't that how uninitialized memory is filled in debug mode?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 
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.

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You