Home Dashboard Directory Help

EndDialog in OnInitDialog reopen Dialog by CProbst1


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 763947
Opened: 9/20/2012 10:52:31 PM
Access Restriction: Public
User(s) can reproduce this bug


Calling EndDialog in OnInitDialog - which documentation explicitly permits - is causing the dialog to open a second time. Changed behaviour in MFC 110.
Sign in to post a comment.
Posted by Microsoft on 4/15/2013 at 1:28 PM
Good news. We are now planning to have a fix for this in VS Update 3. This VSUpdate fix will not be the same as the fix for the next VS version, because that fix would break binary compatibility. There is also a relatively simple workaround that may be an option for you, if you can modify all of your dialog class code, or if your dialogs share a comman base that can be modified. I will share that workaround on the "Workarounds" page.
Posted by Microsoft on 12/4/2012 at 5:19 PM
The fix went in for the next major visual studio release (not part of the next VS2012 updates.

Posted by Sean Hawkins on 12/3/2012 at 5:35 PM
This was marked as fixed on 09/24/2012, however the VS2012 Update 1 did not include this fix. How does one get the fix for this?
Posted by Microsoft on 9/24/2012 at 3:24 AM
Thanks for your update. We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by CProbst1 on 9/21/2012 at 3:48 AM
Run the sample and open "About" Dialog in system menu. You will get two messages where only should be one.
Posted by Microsoft on 9/21/2012 at 3:37 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. In order to fix the issue, we must first reproduce the issue in our labs. We are unable to reproduce the issue with the steps you provided.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

Please submit this information to us within 4 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 9/20/2012 at 11:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Scot Br - MSFT on 4/15/2013 at 1:42 PM
If you can modify your dialog code, and/or your dialogs share a common base class that you can modify, this workaround might be acceptable for you, and resembles the fix to be implemented in the next MFC version. In your dialog class, add a Boolean variable to track whether the dialog was closed by EndDialog:

bool m_bClosedbyEndDialog;

In your constructor or initializer, initialize this variable to false:

m_bClosedbyEndDialog = false;

Add a new function that you will use instead of EndDialog. Have this function set the variable to true, and then call CDialog::EndDialog from within:

void CMyDialog::EndThisDialog(int nResult)
     m_bClosedByEndDialog = true;

Override CDialog::DoModal in your own class, and copy all the code from CDialog::DoModal. Modify the following lines to check the variable, and then reset it:

if (!CreateRunDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), hInst) && !m_bClosedByEndDialog)             {
    // If the resource handle is a resource-only DLL, the dialog may fail to launch. Use the
    // module instance handle as the fallback dialog creator instance handle if necessary.
    CreateRunDlgIndirect(lpDialogTemplate, CWnd::FromHandle(hWndParent), AfxGetInstanceHandle());

m_bClosedByEndDialog = false;
File Name Submitted By Submitted On File Size  
EndDialogTest.zip (restricted) 9/21/2012 -