Home WinHelp HTML Help MS Help 2.0 LongHorn Help Store Links Betas Projects  
 

Using HTML Help with VB.NET

HTML Help in VB.NET: The Basic Problem, Solved
November 7, 2003

As many of you know, the use of HTML Help from VB.NET hasn't been documented yet. MS KB #317406 documents how to call the HTML Help API via unmanaged code from a C# app, but it uses the DLLImport gobbledygook ... hardly a clean solution, that doesn't translate well to VB.NET anyway. (Yeah, Ralph, I know ... VB ain't clean anyhow ... I can hear ya' already ...)

To recap, here are the basic declaration requirements to call HTML Help from VB5/6:

Private Const HH_DISPLAY_TOC = &H1

Private Declare Function HTMLHelp Lib "hhctrl.ocx" _
Alias "HtmlHelpA" (ByVal hWnd As Long, _
 ByVal lpHelpFile As String, _
 ByVal wCommand As Long, _
 ByVal dwData As Long) As Long

Many folks have tried to use this particular set of declarations in VB.NET and have failed. I've been failing at this for a couple years now. However, looking at the C# code in MS KB #317406 gives us a hint:

// This overload is for passing a single uint value as the dwData parameter.
[DllImport("hhctrl.ocx", CharSet=CharSet.Unicode, EntryPoint="HtmlHelpW")]
protected static extern int HtmlHelp
( int caller, String file, uint command, uint data );

Yeah, ok ... different integer types in a couple spots. Got it. From there, it was a matter of finding out what went where. I found one change that is absolutely essential. Following are VB.NET HTML Help declarations that finally work:

Private Const HH_DISPLAY_TOC As Short = &H1
' The first parameter of the call MUST be an Integer type
Private Declare Function HTMLHelp_BaseCall Lib "hhctrl.ocx" Alias "HtmlHelpA" _
(ByVal hWnd As Integer, _
ByVal lpHelpFile As String, _
ByVal wCommand As Long, _
ByVal dwData As Long) As Long

Make the first parameter's Integer type a Long as in the declaration we're used to and it will fail every time. That's the wall everyone has been running into.

To use this is quite simple, and really hasn't changed:

Dim RetVal As Long
RetVal = HTMLHelp_BaseCall(0, "sol.chm", HH_DISPLAY_TOC, 0)

I'm now working on a sample to go on this site. Sooner or later, I'll also complete the VB5/6-converted-to-VB.NET class module to hold all of it.