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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The source code might help.
richpAuthor Commented:
CCommonLogin login(m_pMainWnd,login_name,server_name);
if (login.DoModal()!=IDOK)
    return FALSE;

mktSetManager = new CMarketSetManager;
mktSetManager->Create(IDD_MARKETSET_DIALOG, m_pMainWnd);

Tommy HuiEngineerCommented:
Where in your source code did you get the access violation?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

richpAuthor Commented:
In the InitDialog of the Create(IDD_MARKETSET...
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.
richpAuthor Commented:
This is already being done...

BOOL CMarketSetManager::OnInitDialog()


Where in InitInstance is the dialog code called? Are you sure that m_pMainWnd has a valid window handle at that point?
richpAuthor Commented:
The first dialog is called after the:
      CMainFrame* pMainFrame = new CMainFrame;

      if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
            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).

richpAuthor Commented:
The problem was a bad text pointer and length in the GetItem.

Please remove this question now that you have answered it (can you submit you own answer?)

Alternatively, reduce the value of the question to 0 points so other experts don't waste thier time reading all this only to discover that you've answered the question yourself.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.