Why am I seeing a crash when trying to call CDHtmlDialog::OnInitDialog()
Posted
by Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2010-04-16T19:26:11Z
Indexed on
2010/04/17
0:33 UTC
Read the original article
Hit count: 408
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
// i try to get version info
//set the title
CModuleVersion ver;
char filename[ _MAX_PATH ];
GetModuleFileName( AfxGetApp()->m_hInstance, filename, _MAX_PATH );
ver.GetFileVersionInfo(filename);
// get version from VS_FIXEDFILEINFO struct
CString s;
s.Format("Version: %d.%d.%d.%d\n",
HIWORD(ver.dwFileVersionMS), LOWORD(ver.dwFileVersionMS),
HIWORD(ver.dwFileVersionLS), LOWORD(ver.dwFileVersionLS));
CString version = ver.GetValue(_T("ProductVersion"));
version.Remove(' ');
version.Replace(",", ".");
title = "MyApp - Version " + version;
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 - why it works on some machins and crashes on others.
Both have VS2008 installed
EDIT:
VS versions
VISTA - no crashes 9.0.30729.1 SP
2003 server: (crashes) 9.0.21022.8 RTM
© Stack Overflow or respective owner