Call HHA_COMPILEHHP compile CHM project

Source: Internet
Author: User
Tags assert bool valid

There are two methods of compiling a CHM project (. hhp):

Call Hhc.exe

Call HHA_COMPILEHHP

Call Hhc.exe compile with the following code:

// strChmFileName为你的hhp文件的长文件名
CString strCmdLine;
strCmdLine = "hhc.exe ";
strCmdLine += strChmFileName;
WinExec(strCmdLine, SW_SHOWNORMAL);

There are many drawbacks to invoking this method, first, there is no compilation progress, no prompts, and according to my tests, there is no support for the file names with spaces. The general professional CHM production software is called the Hha.dll in the HHA_COMPILEHHP function to compile. We do not discuss how to generate a CHM engineering file here, which can refer to the files generated by the HTML Help Workshop. Call HHA_COMPILEHHP, Microsoft did not provide function declarations, nor did it provide help information. (it is said to sign the agreement with Microsoft, before you can get the function declaration and related headers) reference to an online introduction using Delphi to implement function calls, plus my little experiment, finally I VC realized. OK, let's see how I do it.

First of all, HHA_COMPILEHHP parameters:

(const char*, LPVOID, LPVOID, int)

The first parameter is the HHP file name you want to compile

The second parameter is the compile log callback function

The third parameter is the compile progress callback function

The fourth parameter doesn't know what to use, I put him to 0

Start writing code.

///////////////////////////////////
Here is a declaration of two callback functions
BOOL CALLBACK Funlog (char* pstr);
BOOL CALLBACK Funproc (char* pstr);
//
Compilehhp
Call HHA_COMPILEHHP compile CHM project
Parameters: Pzfilename for HHP file name to be compiled
Author: Wu Huaihan (wuhran@126.com)
blog:http://blog.sina.com.cn/u/1272907062
////////////////////////////////////////////////////////////////////////////////////
void Ccompilechmdemodlg::buildchmfile (CString strhhpfile)
{
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 is valid, call the function.
LPCSTR Pzfilenmae = Strhhpfile.getbuffer (Strhhpfile.getlength ());
if (fruntimelinksuccess = (procadd!= NULL))
{
if (Procadd (Pzfilenmae, Funlog, Funproc, 0))
{
}
}

Free the DLL module.
Ffreeresult = FreeLibrary (hInstLib);
}

if (M_pstatusbar)
M_pstatusbar->setpanetext (0, "compile complete!") ");
If Unable to call the DLL function, use a alternative.
if (! fruntimelinksuccess)
printf ("message via alternative method\n");

}
//////////////////////////////////////////////////////////////////////////////////////
Funlog ()
Compile Log callback function
Parameters: Log String
Author: Wu Huaihan (wuhran@126.com)
blog:http://blog.sina.com.cn/u/1272907062
////////////////////////////////////////////////////////////////
BOOL Funlog (char* pstr)
{
ASSERT (PSTR);
CString STRMSG;
Strmsg.format ("%s", pstr);
AfxMessageBox (STRMSG);

return true;
}
//////////////////////////////////////////////////////////////
//
Funproc ()
Compile Progress callback function
Parameters: Progress String
Author: Wu Huaihan (wuhran@126.com)
blog:http://blog.sina.com.cn/u/1272907062
//////////////////////////////////////////////////////////////
BOOL Funproc (char* pstr)
{
ASSERT (PSTR);
CString STRMSG;
Strmsg.format ("%s", pstr);

AfxMessageBox (STRMSG);

return true;
}

Contact Method:

Wuhran@126.com

http://blog.sina.com.cn/u/1272907062

The above test code is compiled under VC6.0+WIN2003, please make sure that the Hha.dll file exists in the current directory of your system directory or program.

Welcome everyone to Exchange corrections ...

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.