Patel
Patel

Reputation: 439

HTMLHelp function crashes on 64bit application

I am integrating context specific help for my MFC winforms application. Calling following function crashes my application and hhctrl.ocx is the culprit as per crash log. I think the problem is with 64bit version of hhctrl.ocx in System32 bit folder since my application works fine in 32 bit mode. I tried registering both 32bit and 64bit ocx but that didn't help.

//added following line in InitInstance of application
DWORD m_dwCookie;
HtmlHelp(NULL, NULL, HH_INITIALIZE,(DWORD)&m_dwCookie);

I know this is very very old API for html help integration. Is there an alternate framework for helpfile integration into MFC application if I can't get around the issue?

Upvotes: 1

Views: 549

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51894

There is a problem in your code, in the last parameter of the HtmlHelp call. You cast this to a DWORD value, which you shouldn't. This will work on 32-bit systems, where a pointer (address) is a 32-bit value but, on 64-bit platforms/builds, a pointer is 64-bits, so your cast to DWORD will wipe out the upper 32-bits, leaving an invalid address when it is then (automatically) 're-promoted' to a 64-bit value.

What you need to use is the DWORD_PTR type, instead (the size of which will vary between platforms, 32- or 64-bits, as required):

DWORD m_dwCookie;
HtmlHelp(NULL, NULL, HH_INITIALIZE, (DWORD_PTR)&m_dwCookie); // DWORD_PTR != DWORD

Upvotes: 2

Related Questions