現在我有以下的MFC SDI應用程序代碼,這個代碼來自我的視圖類:在MFC SDI應用改變了這個指針值
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;
}
正如你所看到的,我叫UpdateFpgaAttrib一個CDialog派生類,我在OnItemUpdate函數中實例化了這個函數,這個函數在發佈菜單命令時調用,然後彈出對話框窗口,在對話框中有一個按鈕,點擊後會調用屬於視圖的 SetItemFpgaAttrib函數類,
((CNew_demo_appView*)this->GetParent())->SetItemFpgaAttrib(0,info);
這裏的問題是,當這種 SetItemFpgaAttrib使用該指針引用一些數據,它總是有一些訪問衝突錯誤,當我調用其他的視圖類功能這一功能,這是確定,
void CNew_demo_appView::test()
{
SetItemFpgaAttrib(0,this->GetDocument()->fpga_info)
}
觸發時通過彈出對話框按鈕,它會引起問題,我在SetItemFpgaAttrib上設置了斷點,我發現這個指針的值是正常的0x0041237f的東西,但是當被按鈕觸發時,它總是0x00000001,GetDocument調用總是會引起問題。爲什麼這個指針值發生了變化,是由上下文還是其他引起的?我正在使用Vs2008 SP1