HH_GET_LAST_ERROR
Returns information about the last error that occured.
Argument | Description |
---|---|
hwndCaller | Ignored |
pszFile | must be nil |
uCommand | HH_GET_LAST_ERROR |
dwData | pointer to a THHLastError record |
Return value:
On failure 0, On success non-zero
Description:
The HH_GET_LAST_ERROR returns information about the last error that occured in the HTML
Help Active X control (hhctrl.ocx). It returns both an error code as well as an error
string which are returned in the THHLastError record. Note that this command does not
always return usefull - if any - information. even when the previous command returned 0,
see the text accompanying the example below for more information. Also keep in mind that
the description member of the THHLastError record is really a BSTR and hence needs to be
free by calling SysFreeString().
Example:
The code snippet below attempts to display the default topic of
a helpfile named JediHtmlHlp. Unfortunately I misspelled the filename (should have been:
JediHtmlHelp). The call will fail and the resulting error string will be: "The
compiled help (.chm) file could not be found.". Note that the first hint to the
HH_DISPLAY_TOPIC command failure is that it returns a window handle with a value of 0. If
it had been non zero then at least a help window was displayed. That however, does not
necessarily mean that the requested topic was displayed! For example, if you would attempt
to show a specific topic but that topic doesn't exist in the specified helpfile then the
helpwindow will still be displayed (and a valid handle would be returned). However, the
helpwindow would show a generic "The page could not be displayed" topic. In this
particular case the HH_GET_LAST_ERROR would still return a failure code but without an
associated description (LastError.Description would be nil).
var
LastError: THHLastError;
Wnd: HWND;
begin
Wnd := HtmlHelp(0, PChar('JediHtmlHlp.chm'),
HH_DISPLAY_TOPIC, 0);
if (Wnd = 0) and
(HtmlHelp(0, nil, HH_GET_LAST_ERROR,
DWORD(@LastError)) <> 0) then
begin
if Failed(LastError.hr) then
begin
if LastError.Description <> nil
then
begin
ShowMessage(LastError.Description);
SysFreeString(LastError.Description);
end;
end;
end;
end;
Known errorcodes
Below is a table of known errorcodes returned by the various commands. This is by know
means an extensive table and definitely are not all possible errorcodes, just the ones I
cam across. The "Error code" column contains the value of THHLastError.hr (shown
as an integer) and the "Description" column contains the accompanying value of
the THHLastError.Description field.
Error code | Description |
---|---|
-2147467259 | This is not an errorcode. It indicates success! |
-2147220982 | The compiled help (.chm) file does not contain context IDs (HH_HELP_CONTEXT) |
-2147220991 | The compiled help file (.chm) could not be found |
-2147220981 | Cannot find the requested help topic. This link may be incorrectly authored. Use search or the index to find the topic (HH_HELP_CONTEXT) |
Notes:
The HH_GET_LAST_ERROR command is documented in the HTML Help API Reference but does not
appear in the htmlhelp.h header file.
See also:
THHLastError