We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

MFC Modeless Dialog Problem

richp
richp asked
on
Medium Priority
511 Views
Last Modified: 2008-02-01
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.
Comment
Watch Question

Commented:
The source code might help.

Author

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 HuiEngineer

Commented:
Where in your source code did you get the access violation?

Author

Commented:
In the InitDialog of the Create(IDD_MARKETSET...
I have a CListCtrl in the dialog and a GetItem fails.

Commented:
In the InitDialog of CMarketSetManager you've to call CDialog::OnInitDialog() before triing to access a control either by a control variable or GetDlgItem.

Author

Commented:
This is already being done...

BOOL CMarketSetManager::OnInitDialog()
{
      CDialog::OnInitDialog();

.....

Commented:
Where in InitInstance is the dialog code called? Are you sure that m_pMainWnd has a valid window handle at that point?

Author

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.

Commented:
So OnInitDialog() is called before dialog is physiqualy created try to put initialisation in OnShowWindow ( with a flag to ensure one shot).

Author

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


Commented:
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.

Thanks

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.