Use Hha. DLL to generate a CHM-format e-book

Source: Internet
Author: User

Joymobiler, a mobile phone ebook expert v2.3, was released using Hha. DLL is used to compile and generate CHM e-books. It has been tested and supported: Running in Windows XP, Windows 2000/2003, and Windows 200/Vista environments. However, the compressed packages have changed from over 600 KB to over kb, resulting in a lot of attacks, mainly Hha. DLL has more than 800 K.

Below is a cchm class of your own package

Typedef bool (winapi * myfunc) (const char *, lpvoid, lpvoid, INT );

Class cchm
{
Public:
Cchm ();
Virtual ~ Cchm ();

Public:
Void addchapter (cChapter chap );
Bool preparechm (cstring & sbookname, cstring & sauth, cstring & smaker, cstring & sappdir, cstring & sfilepath );
Bool makechm ();
Carray <cChapter, cChapter &> m_arychapters;

Protected:
Cstring m_sappdir;
Static bool callback funlog (char * pstr); // log callback function
Static bool callback funproc (char * pstr); // compile progress callback function

PRIVATE:
Hinstance m_hinstlib;
Myfunc procadd; // hha_compilehhp function in Hha. dll
Cstring m_sindex; // home page string of the CHM home directory
Cstring m_shhp; // HHP string
Cstring m_shhc; // HHC string
Cstring m_shhcitem; // subdirectory string
Cstring m_sbookname;
};

Cchm: cchm ()
{
M_hinstlib = loadlibrary ("Hha. dll ");
Procadd = NULL;
// If the handle is valid, try to get the function address.

If (m_hinstlib! = NULL)
{
Procadd = (myfunc) getprocaddress (m_hinstlib, "hha_compilehhp ");
}

// Define HHP, HHC, and other file content
M_sindex = _ T ("<HTML> M_shhp = _ T ("[Options]" R "ncompatibility = 1.1 or later" R "ncompiled file = % s" R "ncontents file = HHC. HHC "R" ndisplay compile progress = No "R" nlanguage = 0x804 Chinese (China) "R" N "R" N [files] "R" nindex.htm "R" N "R" N [infotypes] "R" N "R" N ");
M_shhc = _ T ("<! Doctype HTML public ""-// IETF // dtd html // en ""> "R" n <HTML> "R" n M_shhcitem = _ T ("<li> <object type =" "text/sitemap" ">" R "n <Param name =" "name" "value =" "% s ""> "R" n <Param name = "" local "" value = "" mongod.txt ""> "R" n </Object> "R" N ");
}

Cchm ::~ Cchm ()
{
Freelibrary (m_hinstlib );
}

///////////////////////////////////// /////
// Add a directory chapter
// parameters: chapter
// Author: freemobile
// Website: Tumo mobile Park (http://www.joymo.cn)
///////////////////////////////////// ////
void cchm:: addchapter (cChapter chap)
{< br> m_arychapters.add (CHAP );
}< br> ///////////////////////////////// ////////
// compile and create the CHM document
// parameters:
// Author: freemobile
// Website: Tumo mobile Park (http://www.joymo.cn)
///////////////////////////////////// ////
bool cchm:: makechm ()
{< br> cstring sfilename;
try
{< br> sfilename. format ("% s" "HHP" "% S. HHP ", m_sappdir, m_sbookname);
lpcstr pzfilenmae = sfilename. getbuffer (sfilename. getlength ();

If (procadd! = NULL)
{< br> procadd (pzfilenmae, funlog, funproc, 0); // compiled www.joymo.cn
}< br> else
return false;

Sfilename. releasebuffer ();
}
Catch (cexception * E)
{
E-> Delete ();
Return false;
}
Return true;
}
//////////////////////////////////////// //
// Prepare for CHM Compilation
// Parameter: name, author, producer, and ApplicationProgramDirectory, generated file name
// Author: freemobile
// Website: Tumo mobile Park (http://www.joymo.cn)
//////////////////////////////////////// //
Bool cchm: preparechm (cstring & sbookname, cstring & sauth, cstring & smaker, cstring & sappdir, cstring & sfilepath)
{
If (m_arychapters.getsize () <1)
Return false;

Cstring sfilemsg;
Cstring sdir, stmp;
Cfile file;

M_sappdir = sappdir;
M_sbookname = sbookname;

Sdir. Format ("% s" "HHP", m_sappdir );
DWORD dwattr = getfileattributes (sdir );
If (dwattr =-1 | (dwattr & file_attribute_directory) = 0) // The directory does not exist
{
If (! Createdirectory (sdir, null) // create the HHP project directory
{
Return false;
}
}

Sfilemsg. Format (m_sindex, sbookname, sauth, smaker );
Try
{
// Generate the Master Directory display file index.htm
If (file. Open (sdir + "index.htm", cfile: modecreate | cfile: modewrite | cfile: typebinary ))
{
File. writehuge (sfilemsg, sfilemsg. getlength ());
File. Close ();
}
Else
Return false;

// Generate the content file required by the HHP project and the level-2 directory structure of the HHC
Sfilemsg. Empty ();
For (INT I = 0; I <m_arychapters.getsize (); I ++)
{
CChapter chap = m_arychapters.getat (I );
If (chap. m_nfmt = fmt_txt)
{
Stmp. Format (m_shhcitem, chap. m_stitle, I );
Sfilemsg + = stmp;
Sdir. Format ("% s" "HHP" "mongod.txt", m_sappdir, I );
File. Open (sdir, cfile: modecreate | cfile: modewrite | cfile: typebinary );
File. writehuge (chap. m_scontent, chap. m_nlen );
File. Close ();
}
}

// generate HHC. HHC directory file
stmp. format (m_shhc, sbookname, sfilemsg);
sdir. format ("% s" "HHP" "HHC. HHC ", m_sappdir);
file. open (sdir, cfile: modecreate | cfile: modewrite | cfile: typebinary);
file. writehuge (stmp, stmp. getlength ();
file. close ();

// Generate the HHP project file
Stmp. Format (m_shhp, sfilepath );
Sdir. Format ("% s" "HHP" "% S. HHP", m_sappdir, sbookname );
File. Open (sdir, cfile: modecreate | cfile: modewrite | cfile: typebinary );
File. writehuge (stmp, stmp. getlength ());
File. Close ();
}
Catch (cexception * E)
{
E-> Delete ();
Return false;
}


Return true;
}

Bool cchm: funlog (char * pstr)
{
Assert (pstr );
Return true;
}

Bool cchm: funproc (char * pstr)
{
Assert (pstr );
Return true;
}

The call sequence is addchapters ()-> preparechm ()-> makechm (), which is very simple to use. HHP and HHC are pre-formatted strings, and the configurations required for the HHP project are set in preparechm. The HHP and HHC formats are simple. install an HTML Help Workshop to generate one by yourself. You can check the content clearly.

 

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.