tags:

views:

212

answers:

3

I added a helpAbout menu item to my mfc app. I decided to make the ddlg derive from CDHTMLDialog.

I override the OnInitDialog() method in my derived class and the first thing I do is call the parent's OnInitDialog() method.

I then put in code that sets the title.

On some machines this works fine, but on others it crashes in the call to

CDHtmlDialog::OnInitDialog() - Trying to read a null pointer.

the call stack has nothing useful - it is in mfc90.dll

Is this a potential problem with mismatches of mfc/win32 dlls?

It works on my vista machines but crashes on a win2003 server box.

BOOL HTMLAboutDlg::OnInitDialog()
{
   // CRASHES on the following line
    CDHtmlDialog::OnInitDialog();
    CString title = "my title";  // example of setting title

     ...        other code

    SetWindowText(title);
    return TRUE;  // return TRUE  unless you set the focus to a control
}

And here is the relevant header file:

class HTMLAboutDlg : public CDHtmlDialog
{
    DECLARE_DYNCREATE(HTMLAboutDlg)

public:
    HTMLAboutDlg(CWnd* pParent = NULL);   // standard constructor
    virtual ~HTMLAboutDlg();
// Overrides
    HRESULT OnButtonOK(IHTMLElement *pElement);
    HRESULT OnButtonCancel(IHTMLElement *pElement);

// Dialog Data
    enum { IDD = IDD_DIALOG_ABOUT, IDH = IDR_HTML_HTMLABOUTDLG };

protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    virtual BOOL OnInitDialog();

    DECLARE_MESSAGE_MAP()
    DECLARE_DHTML_EVENT_MAP()
};

I can't figure out what is going on - specifically why it works on some machines and crashes on others.

Both have VS2008 installed

Visual Studio reports the following for each machine:

VISTA - no crashes 9.0.30729.1 SP

2003 server: (crashes) 9.0.21022.8 RTM

EDIT - html code

<HTML>
<BODY ID=HTMLAboutDlg BGCOLOR=WHITE>

<TABLE WIDTH=100%>
<TR WIDTH=100% HEIGHT=75>
<TD ALIGN=CENTER VALIGN=TOP>
<font color="#707880">by </font><a ID=LinkCP target=_blank href='http://www.mywebsite.com'&gt;&lt;font color="#000000">my</font><font color="#2554C7">web</font><font color="#7093DB">site</font></a>
</TD>
</TR>
<TR>
<TD ALIGN=RIGHT ALIGN=BOTTOM>
<BUTTON STYLE="WIDTH:80" ID="ButtonOK">OK</BUTTON><BR>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>
A: 

I think you need to call SetHostFlags before calling base class OnInitDialog 'CDHtmlDialog::OnInitDialog()'.

eg. SetHostFlags(DOCHOSTUIFLAG_FLAT_SCROLLBAR); //Set the host UI flags as per your need.

General info: CDHtmlDialog is declared in 'afxdhtml.h'. (I'm sure you would know it)

Since DHtmlDialog internally deals with COM, try having

CoInitialize();//at the begining of application launch

CoUninitialize();//at the exit of app.
AKN
Thanks, I will try that. Can you explain why it works (as is) on one machine and not the other
Tim
A: 

It might be caused by trying to reference a non-existent html file. Make sure the IDH enum you pass to the base class constructor is valid and actually references an existing HTML page.

HTMLAboutDlg::HTMLAboutDlg(Cwnd *pParent) 
    : CDHTMLDialog(HTMLAboutDlg::IDD, HTMLAboutDlg::IDH, pParent)

So, check your IDR_HTML_HTMLABOUTDLG value is actually assigned a correct HTML page.

If you created your dialog with the wizard I think it generated a page for your with the Name like "MyProjectName.htm", normally this is assigned the IDR_HTML_HTMLABOUTDLG value.

Your resource .rc file should probably have a like a little like:

IDR_HTML_MYPROJECT_DIALOG HTML                    "MyProjectName.htm"

Does your HTMLDialogs OnDocumentComplete method get called before OnInitDialog? This happened to me when I twiddled about with this a bit and due to some bad error checking on my part elsewhere it caused the program to crash.

Could you post a stack trace if this doesn't help, or possibly the cpp, h, html and .rc file.

YoungPony
Thanks. The exe and resource are exactly the same. I will check about the ondoccomplete call. The issue is that it works on one platform and not the other. Same source code.
Tim
+1  A: 

Try quoting all the ID attribute values in the HTML, and double-check that the the ID attributes match the references in the DHTML_EVENT_MAP.

I'm guessing that there is differing behavior between IE versions with respect to the case sensitivity of ID attributes or the handling of missing HTML elements. The net effect might be that the base OnInitDialog() class cannot hook up to some of the elements in the document object model on those machines with a particular version of Internet Explorer installed.

Given the history of IE, it's quite possible this behavior crept into one version then was subsequently removed.

This has to be just an educated guess: I don't have access to all the earlier versions of IE to confirm this behavior...

MZB
thanks, good suggestions,. i will try that.
Tim