调用HHA_CompileHHP编译chm工程
编译chm工程(.hhp)有两种方法:1.调用hhc.exe2.调用HHA_CompileHHP
调用hhc.exe编译,代码如下: // strChmFileName为你的hhp文件的长文件名 CString strCmdLine; strCmdLine = "hhc.exe "; strCmdLine += strChmFileName; WinExec(strCmdLine, SW_SHOWNORMAL); 用这种方法调用,有很多缺点,首先,没有编译进度,没有任何提示,根绝我的测试,还不支持有空格的文件名 一般专业的chm制作软件都是调用的hha.dll中的HHA_CompileHHP函数进行编译我们这里不讨论如何生成chm的工程文件,这个可以参考Html Help WorkShop生成的文件调用HHA_CompileHHP,微软没有提供函数声明,也没有提供帮助信息。(据说要和微软签订协议,才可以拿到函数声明及相关的头文件)参考了网上一篇介绍用delphi实现函数调用的文章,加上我的一点试验,终于我VC实现了
ok,看看我是怎么实现的先说下HHA_CompileHHP的参数:(const char*, LPVOID, LPVOID, int)第一个参数为你要编译的hhp文件名第二个参数是编译日志回调函数第三个参数是编译进度回调函数第四个参数不知道什么用,我把他置为0
开始写代码了
// 下面是两个回调函数的声明BOOL CALLBACK FunLog(char* pstr);BOOL CALLBACK FunProc(char* pstr);
//// CompileHHP// 调用HHA_CompileHHP编译chm工程// 参数:pzFileName为待编译hhp文件名// 作者:吴会然(wuhran@126.com)// blog: http://blog.csdn.net/wuhuiranvoid CompileHHP(char* pzFileName){ HINSTANCE hinstLib; typedef BOOL (WINAPI *MYFUNC)(const char*, LPVOID, LPVOID, int);
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; MYFUNC ProcAdd = NULL; // Get a handle to the DLL module. hinstLib = LoadLibrary("hha.dll"); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { ProcAdd = (MYFUNC) GetProcAddress(hinstLib, "HHA_CompileHHP"); // If the function address is valid, call the function. if (fRunTimeLinkSuccess = (ProcAdd != NULL)) { ProcAdd(pzFileName, FunLog, FunProc, 0); } // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } // If unable to call the DLL function, use an alternative. if (! fRunTimeLinkSuccess) printf("message via alternative method/n"); } //
//// FunLog()// 编译日志回调函数// 参数:日志字符串// 作者:吴会然(wuhran@126.com)// blog: http://blog.csdn.net/wuhuiranBOOL FunLog(char* pstr){ ASSERT(pstr); CString strMsg; strMsg.Format("%s", pstr);
// AfxMessageBox(strMsg); return true;}//
// // FunProc()// 编译进度回调函数// 参数:进度字符串// 作者:吴会然(wuhran@126.com)// blog: http://blog.csdn.net/wuhuiran//BOOL FunProc(char* pstr){ ASSERT(pstr); CString strMsg; strMsg.Format("%s", pstr); // AfxMessageBox(strMsg); return true;}//
wuhran@126.comhttp://blog.csdn.net/wuhuiran
上面的测试代码在VC6.0+WIN2003下编译通过请确保你的系统目录或程序当前目录下存在hha.dll文件