ShowHelp function fail notification
Asked Answered
H

1

7

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.

Hieratic answered 6/6, 2016 at 14:4 Comment(10)
The Help class just encapsulates the HTML Help 1.0 engine. And I think the API is designed as returning void and not throwing any exception in error case because this call is very unlikely to fail. You can check if the file exists, and you can test if the chm is opened to the specified topic...Once deployed the chm file is unlikely to be modified by the user ...so is there a case that it can go wrong?Labialized
Can check exe presence?Hieratic
which exe to be exact?Labialized
Your C# application and your application help file (*.CHM) must work together and deployed together. Normally both are installed in your application folder or a subfolder. 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.Stabilize
@Labialized exe which open .chm fileHieratic
The underlying winapi function is too broken to give reliable error information. Looks like it was designed by word-smiths instead of programmers :) HTML help has been deprecated for a long time but pretty hard to get rid of. Only thing you can do about it is test your app and ensure you deploy the necessary .chm files.Dresden
@help.info.de I know application and help file will install at once but I am creating utility for verification before install set creationHieratic
@SantoshDhanawade hh.exe is shipped with the OS (C:\Windows\hh.exe)Labialized
The msdn.microsoft.com/en-us/library/f7y1a1xy(v=vs.110).aspx Help.ShowHelp throws exceptions if an argument is bad, or there are permission issues. If you place the call inside of a try/catch you should be able to detect if there is an exceptional case.Balladmonger
@BerinLoritsch thank you for suggestion. I did but no exception throw for me. :(Hieratic
S
3

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));
    }
}
Stabilize answered 9/6, 2016 at 19:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.