Link to home
Start Free TrialLog in
Avatar of AHD
AHD

asked on

Can Anybody Know what is the problem with this code (using HTMLHelp API function)?

When I run the code bellow I have got a system crashes, can anybody tell me what is the problem?

-----------------------------------------------
void OnHelp()
{
     HINSTANCE inst = LoadLibrary("HHCTRL.OCX");
     (FARPROC&) htmlHelp = GetProcAddress(inst,
                                      "HtmlHelp");
     HWND g = htmlHelp(m_hWnd,                          "C:\\MyHelp.chm",                          2, NULL);
     FreeLibrary(inst);

}
------------------------------------
I suspect that the problem is from the third parameter!!

Pls Help!!!
Avatar of jkr
jkr
Flag of Germany image

The problem is that you do not check whether 'LoadLibrary()' suceeds and 'GetProcAddress()' returns a valid pointer:

void OnHelp()
{
    HINSTANCE inst = LoadLibrary("HHCTRL.OCX");

    if ( NULL == inst) {

    // error
    }
   
    FARPROC htmlHelp = GetProcAddress(inst,
                                     "HtmlHelp");

    if ( NULL == htmlHelp) {

    // error
    }

    HWND g = htmlHelp(m_hWnd,                          "C:\\MyHelp.chm",                          2,
NULL);
    FreeLibrary(inst);

}
Avatar of AHD
AHD

ASKER

No, I have debug the code and the Loadlibrary function executed successfuly, the problem found in htmlHelp function itself, specialy the third parameter I have passed value 2 without knowing what is the exactly value?
In the file HTMLHELP.H, you will see:

#define HH_DISPLAY_INDEX        0x0002  // not currently implemented

so you ar passing in a request for an 'unimplemented command'.  However, another reference indicates that this is an avaialbel command.  If used, you need to pass in a keyword to lookup

Typcial usage is to use (e.g.):

#include <htmlhelp.h>

HWND g = htmlHelp(
        m_hWnd,
        "C:\\MyHelp.chm",
        HH_DISPLAY_TOPIC, // 0
        NULL
);

To lookup a keyword, try:

HWND g = htmlHelp(
        m_hWnd,
        "C:\\MyHelp.chm",
        HH_DISPLAY_INDEX,  // 2
        (DWORD)"Frabisculate"
);


There is extensive on-line infoemation on how to use the HtmlHelp API here:

http://search.microsoft.com/gomsuri.asp?n=1&c=rp_Results&siteid=us/dev&target=http://msdn.microsoft.com/library/en-us/htmlhelp/html/vsconHH1Start.asp

-- Dan
Avatar of AHD

ASKER

Unfortunitly my machine can not find <htmlhelp.h> file,where can I find this file

ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial