问题
I've apparently run into this bug in HTMLHelp, from 2001. (They haven't fixed it yet, but at least they documented it.)
"BUG: HTMLHelp() Opens the Wrong Help File" http://support.microsoft.com/kb/267962/en-us
Their suggested "fix" is for me to rename my CHM files. But I really don't want to do that.
There's more about it here: "The Same CHM Opens Bug" http://kb.helpwaregroup.com/ms-html-help/hh-faq#TOC-The-Same-CHM-Opens-Bug
"The easiest fix is to call FreeLibrary() then LoadLibrary() on the HHCtrl.OCX Library before opening each CHM.
This second solution only works if your application dynamically loads the HH API (HHCtrl.OCX) using LoadLibrary. Applications written in languages such as VB which statically load the API wont be able to do this."
My program is .Net, and I'm using System.Windows.Form.Help.ShowHelp(). Is it maybe possible to cheat by somehow unloading HHCtrl.OCX, for example with p/Invoke? Any other suggestions?
EDIT:
To elaborate: There is a known problem in HTMLHelp that Microsoft has acknowledged in 2001 but never got around to fixing.
In my case I had two help files, "... \Danish\Help.chm" and "... \English\Help.chm". My program opens one or the other depending on which language the user has selected. The problem is that if the user displays help info, then switches languages, and then hits F1 again, the program tries to open the other help file but the help support code re-opens the previously-opened help file instead.
There is a known work-around, but to me it looks like it is only applicable to C++ programs, and my program is .Net. So I'm asking if anyone knows how to apply that work-around, or some other fix, to a .Net program.
回答1:
This may be a bit drastic, but what I ended up doing was launching a new Windows process when I want to display a CHM help file. The tiny process program is a WinForms program, but it does not display its form. It just contains the "Help.ShowHelp(this, chmFileName);" statement in its constructor. (The file name is passed as an argument to the tiny help file process program.)
As an unfortunate side-effect, the process lives on even after the user has closed the help window. But I do kill the process before starting a new one, and when my main program is closing down.
来源:https://stackoverflow.com/questions/11788702/possible-work-around-for-htmlhelp-loading-the-wrong-chm-file