Visual Studio Crash in Add Class Wizard using CDHtmlDialog as the Base Class


Symptoms


When using the Add Class Wizard to wrap a Dialog resource with an MFC class that uses the CDHtmlDialog class as the base class, the Visual Studio IDE may crash.

Cause


This is a bug in the Visual Studio Add Class Wizard scripting code.

Resolution


Currently, there is no hotfix available for this bug. However, to work around you can modify the Add Wizard script code to fix the bug.

Open the default.js file c:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\CodeWiz\MFC\Simple\scripts\1033\default.js  in a text editor.

At line 126, move the CloseResourceFile() function call to after the AddSymbol() call, i.e.

Change

    if (strBaseClass == "CDHtmlDialog")
    {
        RenderAddTemplate(wizard, "dhtmldlg.htm", strHTMLFile, selObj, false);
        oResHelper.OpenResourceFile(strProjectRC);
        var strSymbolValue = oResHelper.AddResource(strHTMLID, strProjectPath + strHTMLFile, "HTML");
        if (strSymbolValue == null) return;    
        oResHelper.CloseResourceFile();
        wizard.AddSymbol("HTML_ID", strSymbolValue.split("=").shift());
    }

To

    if (strBaseClass == "CDHtmlDialog")
    {
        RenderAddTemplate(wizard, "dhtmldlg.htm", strHTMLFile, selObj, false);
        oResHelper.OpenResourceFile(strProjectRC);
        var strSymbolValue = oResHelper.AddResource(strHTMLID, strProjectPath + strHTMLFile, "HTML");
        if (strSymbolValue == null) return;    
        //oResHelper.CloseResourceFile();
        wizard.AddSymbol("HTML_ID", strSymbolValue.split("=").shift());
        oResHelper.CloseResourceFile();
    }

Note that any hotfixes or service packs produced in the future that modify the default.js file may require you to redo these changes.

More Information


You can reproduce the crash with the following steps.
  1. Create a new MFC Application project. Use all default settings
  2. In the new project, open the Resource view
  3. Right-click on the Dialog folder and choose Insert Dialog
  4. Right-click the newly added dialog resource and choose Add Class
  5. Give the new class a name and choose the base class as CDHtmlDialog
  6. Click the Finish button.
The IDE should AV at this point. Modify the default.js file as outlined in the Resolution section and you should be able to create the dialog class without error.