Now I have the following MFC SDI application code,this code comes from my view class:
void CNew_demo_appView::OnItemUpdate()
{
// TODO: Add your command handler code here
int i=this->GetListCtrl().GetSelectionMark();//get the selected item no
this->GetDocument()->unpacker.GetInformation(i,(BYTE*)(&(this->GetDocument()->fpga_info)));
UpdateFpgaAttrib updatefpgadlg;
updatefpgadlg.DisplayInfo(this->GetDocument()->fpga_info);
updatefpgadlg.DoModal();
}
void CNew_demo_appView::SetItemFpgaAttrib(int index,FPGA_INFO info)
{
this->GetDocument()->fpga_items[0]=info;
}
As you can see, I got a CDialog Derived class called UpdateFpgaAttrib, I instantialize it in the OnItemUpdate function which is called when a menu command is issued, then DoModal() Popup the Dialog window, on that dialog, there is a button, when clicked it will call the SetItemFpgaAttrib function which belongs to the View Class,
((CNew_demo_appView*)this->GetParent())->SetItemFpgaAttrib(0,info);
here is the problem, when this SetItemFpgaAttrib references some data using this pointer, it always got some Access Violation Error, when I invoke this function in other View class function, it is ok,
void CNew_demo_appView::test()
{
SetItemFpgaAttrib(0,this->GetDocument()->fpga_info)
}
when triggered by the popup dialog button, it cause problem, I set break point on the SetItemFpgaAttrib , I found the this pointer value is normal 0x0041237f thing, but when triggered by the button ,it is always 0x00000001, the the GetDocument call alway cause problem. Why is the this pointer value changed,is that caused by the context or something else? I am using Vs2008 SP1