Calling EndDialog() within OnInitDialog() causes the dialog to be displayed twice. - by Sean Hawkins

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


6
0
Sign in
to vote
ID 772859 Comments
Status Closed Workarounds
Type Bug Repros 4
Opened 11/29/2012 11:08:43 PM
Access Restriction Public

Description

Calling EndDialog within OnInitDialog causes the dialog to come up twice. It worked correctly in Visual Studio 2008 (MFC9) and Visual Studio 2010 (MFC10), but fails in Visual Studio 2012 Update 1 (MFC11)
 
In addition, the help documentation by Microsoft for CDialog::EndDialog even states that it can be called from within OnInitDialog. However, as stated, it causes the dialog to come up a second time.

This is often used to bring up a dialog with a progress bar on it, do something, and then close when it is done. Because of this BUG, it ends up processing twice.

The problem is caused in dlgcore.cpp (in the MFC code) line 656 where CreateRunDlgIndirect() is called back to back.
Sign in to post a comment.
Posted by Lynn Wei on 11/3/2014 at 9:23 PM
I tried with VS2012 update 4. Same problem. So the fix was not included in the update for VS2012, right? Could you give more details about starting the QFE process? Thanks!
Posted by Microsoft on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 4/15/2013 at 1:30 PM
Good news. We are now planning to have a fix for this in VS 2012 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 common base that can be modified. I will share that workaround on the "Workarounds" page.
Posted by Microsoft on 12/6/2012 at 12:11 PM
Hello Sean,

If that is a major blocking issue for your adoption, please do start a QFE process via http://support.microsoft.com/ where you can get a fix to the exiting VS2012 bits.

Thanks,
Ayman
Posted by Sean Hawkins on 12/4/2012 at 5:22 PM
By waiting until the next major visual studio release to update this, it means that many large projects will be forced to hold off adopting VS2012.

We have a project with 3 million lines of code, over 700 EndDialog() calls. We would have to evalatuate each one to ensure that EndDialog() could not possibly be called before OnInitDialog has returned. From a coding guidelines/QA standpoint, it makes it so the only thing that should ever happen in OnInitDialog is a PostMessage(). Because anything else might call a function that calls EndDialog() and thus introduce a bug.

If Microsoft takes that stance: 1) they are going to break a lot of existing code. 2) they need to update their documentation. 3) they need to list this as a breaking change in VS2012. 4) and ideally, the compiler would need to be able to throw a warning or error that EndDialog is being called from within OnInitDialog.

In addition, the MFC source code itself calls EndDialog() from within OnInitDialog. See afxcolordialog.cpp (line 121), docmgr.cpp (line 563). Which means MFC now has two additional bugs caused by this one.


Posted by Microsoft on 12/4/2012 at 5:16 PM
Thanks for reporting the issue. We will be fixing in the next major visual studio release (not part of the next VSUpdate).

Thanks,
Ayman
Posted by Microsoft on 11/30/2012 at 1:46 AM
Thanks for your feedback.

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 Microsoft on 11/29/2012 at 11:51 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)