Microsoft KB Archive/244140

= BUG: A Fatal Error Occurs If You Run a Microsoft Visual Basic Application by Using the HtmlHelp API =

Article ID: 244140

Article Last Modified on 8/5/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q244140



SYMPTOMS
A Microsoft Visual Basic application that is running in the IDE uses the HtmlHelp function to display a Help window. If you close the calling form or you stop the project, a fatal error occurs. If you use Microsoft Windows 95 or Microsoft Windows 98, the Visual Basic design environment shuts down with no message. If you use Microsoft Windows NT, an access violation occurs. Depending on the operating system that you are using, an invalid page fault (IPF) or an access violation occurs in a compiled program.



RESOLUTION
By default, the HTML Help ActiveX control (Hhctrl.ocx) runs in a second thread. To work around this issue, you must force Hhctrl.ocx to run in a single thread in Visual Basic. You can do this by calling HtmlHelp with the HH_INITIALIZE command when Visual Basic loads, and by calling HtmlHelp with the HH_UNINITIALIZE command when Visual Basic unloads. To run these commands when Visual Basic starts, create an add-in that automatically loads when you start the IDE.

To use this add-in, register HHCTRLAV.dll by using regsvr32. To do this, follow these steps:


 * 1) Click Start, and then click Run.
 * 2) Type regsvr32 c:\HHCtrlAV\HHCtrlAV.dll.
 * 3) Press ENTER.

A message informs you that DLLRegisterServer succeeded.

You must also set up the add-in to be recognized by Visual Basic, and to be loaded when Visual Basic starts. To do this, add HHCTRLAV.Connect=1 to the end of the Vbaddin.ini file. The Vbaddin.ini file is located in C:\Windows or in C:\WinNT.

You can now start Visual Basic. HHCtrlAV is in the list of loaded add-ins. If HHCtrlAV is started when Visual Basic starts (the Load on Startup option is enabled), then you do not receive the access violation in VB5.EXE or VB6.EXE as a result of Hhctrl.ocx.

The source code for this add-in is also included. With this source code, you can modify the add-in. The following file is available for download from the Microsoft Download Center:

HHCtrlAV_AddIn.EXE

http://download.microsoft.com/download/3/1/d/31d348d4-10b3-49e2-ad70-acdff964eeb4/HHCtrlAV_AddIn.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
To reproduce the behavior on Microsoft Windows 2000 and Microsoft Windows XP, follow these steps:  Start a new Visual Basic Standard EXE project. By default, Form1 is created. Add a CommandButton to Form1.  Add the following code to the General Declarations section of Form1: Option Explicit Private Declare Function HtmlHelp Lib "hhctrl.ocx" _ Alias "HtmlHelpA" _ (ByVal hwndCaller As Long, _           ByVal pszFile As String, _            ByVal uCommand As Long, _            ByVal dwData As Long) _ As Long Private Const HH_CLOSE_ALL = &H12 Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) HtmlHelp hWnd, "", HH_CLOSE_ALL, 0& End Sub  Run the project, and then close Form1 when it appears. This reproduces the problem approximately one out of three times.

To reproduce this behavior on Microsoft Windows 95, Microsoft Windows 98, or Microsoft Windows NT 4.0, follow these steps:  Start a new Visual Basic Standard EXE project. By default, Form1 is created.</li> Add a CommandButton to Form1.</li>  Add the following code to the General Declarations section of Form1: Option Explicit

Private Declare Function HtmlHelp Lib "hhctrl.ocx" _ Alias "HtmlHelpA" _ (ByVal hwndCaller As Long, _          ByVal pszFile As String, _           ByVal uCommand As Long, _           ByVal dwData As Long) _ As Long

Private Const HH_DISPLAY_TOPIC = &H0

Private Sub Command1_Click Call HtmlHelp(Me.hWnd, "IEXPLORE.CHM", _                         HH_DISPLAY_TOPIC, 0) End Sub </li> Run the project. Click Command1, and then close the form. Do not close the HTML Help window that appears.</li></ol>

<div class="references_section">