Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShowHelp function fail notification

Tags:

c#

.net

chm

I am newbie in C# and working for utility to verify topic ID content of help files. Following function is useful for me to launch help file:

 Help.ShowHelp(this, HelpFile.Text, HelpNavigator.TopicId, topicIDStr);

In case Help.ShowHelp() function failed to launch .CHM (Help file) with provided CHM file and topic id, then i need to provide notification to user about launch failure.

Following is pseudo code example:

If Help.ShowHelp() failed
{
    Messagebox("Failed to launch help")
}

I search on web but unable to find function or return type/Parameter from ShowHelp() which will notify failure of showHelp() function.

Following things are already tried:

  • Since i am from MFC background i tried to find function related to GetLastError() in C#. As a result getlastwin32error() is suggested but not providing last error in failure condition

  • parameter or return type of Help.ShowHelp() is not useful to find fail condition.

Thanks for reading.

like image 311
Santosh Dhanawade Avatar asked Jun 06 '16 14:06

Santosh Dhanawade


1 Answers

It's difficult to answer because we have not so much information how you are using topicIDStr. Having formatted contextID numbers like shown in my article Creating Context-Sensitive Help for Applications you may check the number range by code.

But again, you have to check all ´topicID's´ while developing your application and authoring your help file. Many things are depending on how help is called from your application.

You may know, the purpose of the two files (ALIAS and MAP) is to ease the coordination between developer and help author (see link above). The mapping file links an ID to the map number - typically this can be easily created by the developer and passed to the help author. Then the help author creates an alias file linking the IDs to the topic names. One can check this externally by FAR HTML. FAR HTML is a toolbox full of various authoring, file and HTML utilities.

enter image description here

Please remember HTMLHelp is about 20 years old and written in C++ by Ralph Walden. The .NET (e.g. VB or C#) Help class is a wrapper for good old HTMLHelp API calls and a quick and dirty coding by Microsoft programmers for managed code. Unmanaged code is the man's way and a second (difficult) solution.

So, when you really want to go deeper into this I'd give some links and information as a starting point. But you have to code for your needs by yourself.

How to use the unmanaged HTML Help API from a managed Visual C# application

Connecting HTML Help to C++/MFC Programs (PDF)

The HH_GET_LAST_ERROR command refers to a missing file Hherror.h which can be found in the following Microsoft KB article.

The HtmlHelp.h file has a comment with HH_GET_LAST_ERROR that say "not implemented" however it appears it is at least partially implemented. If I call HtmlHelp(0, PChar(mHelpFile), HH_HELP_CONTEXT, 911); where 911 is an invalid ContextID, then HH_GET_LAST_ERROR returned Error 0x8004020A with Description text "The compiled help (.chm) file does not contain context IDs." For most types of errors HH_GET_LAST_ERROR appears to return 0x80004005 "Unspecified error".

As an idea only please have a look at: LoadLibrary on OCX file fails in Windows 7 x64

As mentioned by others you may check for e.g. File.Exists and shown in the code sample below for a Process.Start(...) call.

private void button1_Click(object sender, EventArgs e)
{
    string helpFilePath = Application.StartupPath + @"\help-subfolder\C-Sharp-CHM-example.chm";

    // Verify if the file exists
    if (File.Exists(helpFilePath))
    {
        Process.Start(helpFilePath);
    }
    else
    {
        Console.WriteLine(string.Format("File not found [{0}]", helpFilePath));
    }
}
like image 50
help-info.de Avatar answered Sep 28 '22 23:09

help-info.de