Click here to Skip to main content
15,886,026 members
Articles / Mobile Apps

CHMReader.Net

Rate me:
Please Sign up or sign in to vote.
3.71/5 (36 votes)
15 Aug 2004CPOL4 min read 306.5K   1.2K   69   167
This is a new '.NET' version of my CHMReader program, with more features.

Sample Image - chmreader007.jpg

Introduction

In my first article for ‘The Code Project’ I developed a program to view CHM files on a Pocket PC 2003 (Using embedded Visual C++) using the open source CHMLib. This version had a number of issues, so I decided to write a C# version, and here it is.

Sample screenshot

Features

  • Contents Tree
  • Index List with Also See jumping.
  • Search
  • Uses Regular expressions to patch the HTML code extracted from the CHM
  • Handles CHM files which point to other CHM Files (CHM Book Shelf. E.g. MCSD NetCore.chm)Handles navigation to Anchor points
  • Full C# Source included

Sample screenshot

The New Code

The new version of the CHMReader.Net uses the following libraries

A Big thank you to these guys for releasing there code so we can all benefit from it. Thanks.

There are a number of points to make here concerning the porting of the CHMLib. Firstly, when porting LZW decompression code, I had to first compile the code in ‘C’ and get the pre-processor to export the source sent to the compiler. This is because the original code used a lot of macros which made it very difficult to see how to port come sections of the code. Once I had this source I could port the code to C#. I had to convert all the buffer accesses to use .Net Streams, along with the code which read buffers. This included creating special classes with hold the data from the internal structures of the CHM File Stream, and manually reading the data from the CHM file into the data members of the class. (Using BinaryReader.ReadUInt16 etc).

Once I had a version which compiled in C#, I then had to test that the code worked. This was a case of running both versions of the library side by side in 2 instances of Visual Studio 2003 and extracting files from the same CHM file, making source that the output was the same.

Once done, I replaced the base stream handling used by the HTML Help library with the ported library, and then had a working CHM Reader which could extract files, extract help indexes & perform searches using the HTML Help library.

Sample screenshot

The CHMReader

Now that I had the basics working, I then when on to develop the Reader it’s self. Once you have the filename of the page you want to display (From the Index, Contents or search) you can then extract that file from the CHM file. This file then as to be scanned, and the images, frame pages & Style Sheets used by the HTML page need to be extracted, and the HTML patched so that they point to the new location of the files. In this case a temp directory in the filing system. Also at this point I remove XML and Script tags as they are not supported. Once this is done I can then save the file, and use the OpenNetCF library’s HTML Viewer control to view the page as intended.

There is more to it that what I have described, so look that the code. The code is not optimized as yet. This is some that may or may not get done depending on time.

If you can not read a CHM File, please debug the code and post any changes, If you really can not get the CHM file to view, then please email me with the CHM file.

I hope you enjoy this version.

History

V2.0.0Initial Release
V2.0.1 - 27 May 2004
  • Bug Fixes to LZW Decompression
  • Added icon to file
  • Added Command line parameter
  • Added File Association with CHM files (After first run)
  • Created installer
V2.0.3 - 12 July 2004
  • Minor bug fixes.
  • New File Open Dialog to allow browsing of complete file system
V2.0.5 - 14 July 2004
  • HTML Help Library updates included (Orignal code by Klaus Weisser – See //www.codeproject.com/csharp/HtmlHelp.asp)

  • CHMLib 0.35 updates ported to my C# version (Original C++ library, CHMLib, by Jed Wing.)

  • Added a option to allow user to save CHB files - A CHB file is a file which contains the internal data structures which are created when a CHM file is loaded. This option allows this data to be saved to a CHB file. This file can then be loaded next time the same CHM file loaded, and a lot of processing can be avoided. This functionally is thanks to Klaus Weisser. You can also use Klaus Weisser's HtmlHelp viewer to create the CHB files(They need to be renamed from <chmfile.chm.bin> to <chmfile>.CHB and stored in the same directory as the CHM file on the Pocket PC.

  • Minor UI enhancements.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 790546725-Jun-11 23:29
Member 790546725-Jun-11 23:29 
GeneralPorted to Windows Mobile 6.5.3 (start button at bottom) VGA device Pin
yusufat8-Feb-11 21:38
yusufat8-Feb-11 21:38 
QuestionNullReferenceException when opening .chm file Pin
hfrmobile5-Jan-10 18:52
hfrmobile5-Jan-10 18:52 
GeneralMy vote of 1 Pin
hfrmobile5-Jan-10 18:49
hfrmobile5-Jan-10 18:49 
GeneralPorted to Windows Mobile Smartphone Edition Pin
buaa_aladdin8-Jun-08 3:36
buaa_aladdin8-Jun-08 3:36 
NewsI can run it! Pin
Jackey_shao10-Aug-07 16:00
Jackey_shao10-Aug-07 16:00 
QuestionHow abtain CHMLib lib? Pin
Jackey_shao9-Aug-07 0:30
Jackey_shao9-Aug-07 0:30 
QuestionRe: How abtain CHMLib lib? Pin
Jackey_shao9-Aug-07 14:28
Jackey_shao9-Aug-07 14:28 
GeneralPublish just the custom open file dialog Pin
rudiman19-Oct-06 6:44
rudiman19-Oct-06 6:44 
GeneralRe: Publish just the custom open file dialog Pin
Peter Tewkesbury19-Oct-06 21:30
professionalPeter Tewkesbury19-Oct-06 21:30 
GeneralRe: Publish just the custom open file dialog Pin
Jackey_shao8-Aug-07 21:48
Jackey_shao8-Aug-07 21:48 
GeneralRe: Publish just the custom open file dialog Pin
Peter Tewkesbury8-Aug-07 23:33
professionalPeter Tewkesbury8-Aug-07 23:33 
GeneralRe: Publish just the custom open file dialog Pin
Jackey_shao8-Aug-07 23:48
Jackey_shao8-Aug-07 23:48 
GeneralRe: Publish just the custom open file dialog Pin
Peter Tewkesbury9-Aug-07 3:22
professionalPeter Tewkesbury9-Aug-07 3:22 
GeneralRe: Publish just the custom open file dialog Pin
Jackey_shao9-Aug-07 14:47
Jackey_shao9-Aug-07 14:47 
QuestionDirectoryNotFoundException Pin
Korayem.NET4-Sep-06 23:42
Korayem.NET4-Sep-06 23:42 
AnswerRe: DirectoryNotFoundException Pin
Korayem.NET6-Sep-06 20:35
Korayem.NET6-Sep-06 20:35 
GeneralNotSupportedException Pin
Sri harini15-Aug-06 17:11
Sri harini15-Aug-06 17:11 
AnswerRe: NotSupportedException Pin
Pedro Simao23-Aug-06 5:34
Pedro Simao23-Aug-06 5:34 
GeneralUnexpected error has occurred in chmreader.net.exe Pin
GodlyDevil13-Feb-06 17:19
professionalGodlyDevil13-Feb-06 17:19 
QuestionRe: Unexpected error has occurred in chmreader.net.exe Pin
lsantillo18-Feb-06 3:06
lsantillo18-Feb-06 3:06 
AnswerRe: Unexpected error has occurred in chmreader.net.exe Pin
Pablo Alarcón García3-Apr-06 1:59
Pablo Alarcón García3-Apr-06 1:59 
AnswerRe: Unexpected error has occurred in chmreader.net.exe Pin
AlexNek25-Jan-07 7:48
AlexNek25-Jan-07 7:48 
QuestionRe: Unexpected error has occurred in chmreader.net.exe Pin
snoopy9931-Jul-07 8:15
snoopy9931-Jul-07 8:15 
GeneralRe: Unexpected error has occurred in chmreader.net.exe Pin
Jackey_shao9-Aug-07 15:17
Jackey_shao9-Aug-07 15:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.