I am writting a MFC based program in VS2010 based on static libraries and in the linker with "No incremental" linking option(I add the code to the post).
The project has no problem in building in in VS 2010, and it actually shows the dialog window with the values in "virtual BOOL OnInitDialog() ". But when a run it, it seems that the CDialog is lost and it crashes. After debugging, i found out that the casted pointers for any of the elements of the windows, i.e. buttons, edit box or combobox, always gets a hWnd=???? value. For instance, at the moment i only want to write in pSerial->ShowWindow(False) which simply makes the program crash with an Assertion of "Access violation reading location 0x00000020."
In addition, I found out, also by debuging, that the actual pointers for pSERIAL, pCANCEL etc. have a meaningfull value before the program gets out from the constructor: "virtual BOOL OnInitDialog() ". It seems that the return true functions leads to "dlgcore.cpp", where the return shown below resets all values. I do not understand that to be honest.
//Called right after constructor. Initialize things here.
virtual BOOL OnInitDialog()
{
/**
ERROR HERE???
You now declare and use some local variables - which will be
destroyed after this OnInitDialog function finishes - you probably meant to use
the Global variable you declared earlier??? **/
// setting pointer to window objects
CDialog::OnInitDialog();
CEdit * pOUTPUT = (CEdit *) GetDlgItem(CE_SHOW);
CEdit * pINPUT = (CEdit *) GetDlgItem(CE_BOX);
CComboBox * pCHOICE = (CComboBox *) GetDlgItem(CB_CHOOSE);
CButton * pSERIAL = (CButton *) GetDlgItem(CB_SERIAL);
CButton * pCANCEL = (CButton *) GetDlgItem(CB_CANCEL);
// Setting default values to Combo Box Menu
pCHOICE->AddString(L"msg1");
pCHOICE->AddString(L"msg2");
// Setting default values to Editing point
pINPUT->SetWindowText(L"Hi Y'all!");
pOUTPUT->SetWindowText(L"Your Output is shown here...");
returntrue;
}
Deleting on OnInitDialog de Cedit * before pOUTPUT have solved the problem. My OnInitDialog now looks like the following one and it is executed with no problems.