richp
asked on
MFC Modeless Dialog Problem
In the InitInstance of my app I create a modal dialog, close it, then create a modeless dialog box. This worked when built using static mfc but when I switched the project to shared MFC and using run time library multithreaded dll, I receive an access violation in the second initdialog. A getitem for a clistctrl is failing.
The source code might help.
ASKER
CCommonLogin login(m_pMainWnd,login_nam e,server_n ame);
if (login.DoModal()!=IDOK)
return FALSE;
mktSetManager = new CMarketSetManager;
mktSetManager->Create(IDD_ MARKETSET_ DIALOG, m_pMainWnd);
if (login.DoModal()!=IDOK)
return FALSE;
mktSetManager = new CMarketSetManager;
mktSetManager->Create(IDD_
Where in your source code did you get the access violation?
ASKER
In the InitDialog of the Create(IDD_MARKETSET...
I have a CListCtrl in the dialog and a GetItem fails.
I have a CListCtrl in the dialog and a GetItem fails.
In the InitDialog of CMarketSetManager you've to call CDialog::OnInitDialog() before triing to access a control either by a control variable or GetDlgItem.
ASKER
This is already being done...
BOOL CMarketSetManager::OnInitD ialog()
{
CDialog::OnInitDialog();
.....
BOOL CMarketSetManager::OnInitD
{
CDialog::OnInitDialog();
.....
Where in InitInstance is the dialog code called? Are you sure that m_pMainWnd has a valid window handle at that point?
ASKER
The first dialog is called after the:
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(ID R_MAINFRAM E))
return FALSE;
m_pMainWnd = pMainFrame;
m_pMainWnd has a valid pointer after that.
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(ID
return FALSE;
m_pMainWnd = pMainFrame;
m_pMainWnd has a valid pointer after that.
So OnInitDialog() is called before dialog is physiqualy created try to put initialisation in OnShowWindow ( with a flag to ensure one shot).
ASKER
The problem was a bad text pointer and length in the GetItem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.