且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML帮助研讨会成功编译.chm文件后返回错误

更新时间:2023-09-29 10:58:46

HTML帮助研讨会已安装了2个主要可执行文件:

HTML Help Workshop is installed with 2 main executables:


  1. hhc.exe 是HTML帮助编译器的控制台版本。

  2. hhw.exe 是HTML帮助编译器的 Windows GUI版本。

  1. hhc.exe is the console version of the HTML Help Compiler.
  2. hhw.exe is the Windows GUI version of HTML Help Compiler.

但这两个可执行文件并不直接完成HTML帮助项目(hhp)到已编译HTML(chm)的编译。

But the compilation of the HTML Help Project (hhp) to Compiled HTML (chm) is not directly done by those two executables.

两者均用于编译 hha.dll -HTML帮助作者库-通过调用导出的函数 HHA_CompileHHP

Both use for compilation hha.dll - the HTML Help Author library - by calling the exported function HHA_CompileHHP.

该库的导出函数为:


  • EditHhCtrlObject

  • EditHhCtrlScript

  • FreeFilterDIB

  • HHA_Comp ileHHP

  • LoadFilterImage

  • LoadJpeg

  • EditHhCtrlObject
  • EditHhCtrlScript
  • FreeFilterDIB
  • HHA_CompileHHP
  • LoadFilterImage
  • LoadJpeg

Microsoft有据我所知,没有发布任何文档或这些函数的函数声明。

Microsoft has not published any documentation nor the function declarations of those functions as far as I know.

假设是通过一些使用 hhc.exe 表示函数 HHA_CompileHHP 具有 BOOL 作为返回类型,其 int 并成功返回 TRUE ,即值 1 ,失败时 FALSE ,即值 0 。看起来 hhc.exe 使用此返回值而不将其值转换为退出/返回代码。

I suppose from some quick tests with hhc.exe that the function HHA_CompileHHP has BOOL as return type which is int and returns on success TRUE, i.e. the value 1, and on failure FALSE, i.e. the value 0. And it looks like hhc.exe uses this return value without inverting the value as exit/return code.

因此错误级别的 成功为 1 ,失败为 0

Therefore the errorlevel is 1 on success and 0 on failure.

为验证我的假设而进行的测试:

The tests I made to verify my assumption:


  1. 运行HTML帮助编译器,其项目文件名不存在:

  1. Run HTML Help compiler with name of a project file which does not exist:

hhc.exe index_1.hhp




无法打开index_1.hhp。

Unable to open index_1.hhp.

分别的退出代码错误级别为0。此错误消息由 hhc.exe $ c打印$ c>,因为可以在 hhc.exe 中找到错误消息。

The exit code respectively errorlevel is 0. This error message is printed by hhc.exe because the error message can be found in hhc.exe.

设置为只读已存在的输出文件 index.chm 上的文件属性,并运行HTML帮助编译器:

Set read-only file attribute on already existing output file index.chm and run HTML Help compiler:

attrib +r index.chm & hhc.exe index.hhp & attrib -r index.chm




HHC5010:错误:无法打开 C :...文件夹路径... index.chm。编译停止。

HHC5010: Error: Cannot open "C:... folder path ...\index.chm". Compilation stopped.

分别的退出代码错误级别为0。此错误消息由 hha.dll 打印,因为只能在 hha.dll 中找到此错误消息。

The exit code respectively errorlevel is 0. This error message is printed by hha.dll because this error message can be found only in hha.dll.

重命名在 index.hhp 中明确指定的* .htm文件,并运行HTML帮助编译器:

Rename a *.htm file explicitly specified in index.hhp and run HTML Help Compiler:

ren "file.htm" "renamed file.htm" & hhc.exe index.hhp & ren "renamed file.htm" "file.htm"




Microsoft HTML帮助编译器4.74.8702



编译C:...文件夹路径... \index.chm



HHC5003 :错误:编译 file.htm 时编译失败。



未编译以下文件:

file .htm

分别的退出代码错误级别为0。此错误消息也由 hha.dll 打印,因为此错误消息也只能在 hha.dll 中找到。

The exit code respectively errorlevel is 0. This error message is printed also by hha.dll because this error message can be found also only in hha.dll.

所有错误消息均写为处理 STDOUT 而不是 STDERR 作为控制台应用程序的典型值。除了$ 0或1以外,没有其他值分配给错误级别,这就是为什么我认为函数 HHA_CompileHHP 返回一个值的原因。简单的布尔值。

All error messages are written to handle STDOUT and not to STDERR as typical for console applications. There was never another value than 0 or 1 assigned to errorlevel which is the reason why I suppose the function HHA_CompileHHP returns a simple boolean value.

结论:

与通常情况相反例如通过在批处理文件中使用来评估HTML帮助编译的成功/失败:

The opposite as usual must be done to evaluate on success/failure of an HTML Help compilation for example by using in the batch file:

"%ProgramFiles(x86)%\HTML Help Workshop\hhc.exe" index.hhp
if not errorlevel 1 exit /B 1

[OPTIONS] 部分的HTML帮助项目文件(* .hhp文件)中,可以使用错误日志指定日志文件file = ... HHA_CompileHHP 输出的所有消息写入另外并将其打印到 STDOUT

In HTML Help Project file (*.hhp file) in section [OPTIONS] a log file can be specified with Error log file=... into which all messages output by HHA_CompileHHP are written additionally to printing them to STDOUT.

但是在这种情况下,使用 Doxygen 生成* .hhp文件,重定向 STDOUT ,将批处理文件中的日志文件尽管这并不是真正需要的,因为Team Foundation Server很可能已将消息捕获到日志中。 (我没有安装Team Foundation Server。)

But in this case with Doxygen generating the *.hhp file it would be easier to redirect STDOUT in the batch file to a log file although this is also not really needed because most likely the Team Foundation Server is capturing the messages already to a log. (I don't have Team Foundation Server installed.)