Click here to Skip to main content
Email Password   helpLost your password?

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

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.0 Initial 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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionNullReferenceException when opening .chm file
hfrmobile
19:52 5 Jan '10  
I just downloaded and tried to open a .chm file on my MDA Compact IV (.NET CF 3.5 installed) but I got a NullReferenceException when opening a .chm file:

CHMReader.Net.exe
NullReferenceException

bei HtmlHelp.ChmDecoding.CHMFile.SaveDump(DumpingInfo dmpInfo)
bei HtmlHelp.ChmDecoding.CHMFile..ctor(HtmlHelpSystem systemInstance, String chmFile, Boolean onlySystemData, DumpingInfo dmpInfo)
bei HtmlHelp.ChmDecoding.CHMFile..ctor(HtmlHelpSystem systemInstance, String chmFile, DumpingInfo dmpInfo)
bei HtmlHelp.HtmlHelpSystem.OpenFile(String chmFile, DumpingInfo dmpInfo)
bei CHMReader.Net.CHMReader.OpenCHMFile(FileInfo CHMFileInfo)
bei CHMReader.Net.CHMReader.mnuOpen_Click(Object sender, EventArgs e)
bei System.Windows.Forms.MenuItem.OnClick(EventArgs e)
bei System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
bei System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
bei System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
bei Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
bei System.Windows.Forms.Application.Run(Form fm)
bei CHMReader.Net.CHMReader.Main(String[] args)

See also
http://hfrmobile.spaces.live.com/blog/cns!9015C1E219CDFADA!2283.entry[^]


GeneralMy vote of 1
hfrmobile
19:49 5 Jan '10  
NullReferenceException when open .chm file
GeneralPorted to Windows Mobile Smartphone Edition
buaa_aladdin
4:36 8 Jun '08  
Thanks for your great soft. I made a smartphone version derived from your source code, which is hosted at http://code.google.com/p/chmreader-smartphone/[^]

I am not sure if I'm allowed to do so. If not, please contact me and I will remove it. Best regards Smile
NewsI can run it!
Jackey_shao
17:00 10 Aug '07  
Thx,I can run it.For I installed Pocket PC 2003 SDK and run it in that.But I hope that can run of my need.So I can learn it if I have enough time.Thanks very much.My English very poor!Smile
Regards!

shaochangming
QuestionHow abtain CHMLib lib?
Jackey_shao
1:30 9 Aug '07  
Can you introduce your program to using chmlib and how to make lib?
QuestionRe: How abtain CHMLib lib?
Jackey_shao
15:28 9 Aug '07  
Im install CHMReader.WCE420X86.CAB in wince4.2 of Emulator CPU x86:(,This was take place error:ArgumentOutOfRangeException took place error at Application::Run+0x1a CHMReader::Main+0xd5
"OK"should be stop
GeneralPublish just the custom open file dialog
rudiman
7:44 19 Oct '06  
Hello.

I was looking for a custom open file dialog all over the internet until I found this project. Wouldn't it be nice if you released just this class for public use? I guess there are more programmers than me who are fed up with the common dialoges in NETCF. Is it ok to use your class in other project (of course not commercial ones, just private)?

rudiman
GeneralRe: Publish just the custom open file dialog
Peter Tewkesbury
22:30 19 Oct '06  
Hi,

Thanks for the complement

Yes it is fine for you to use the dialog for private use. Just keep/add author/copyright messages in source & about dialog box.

Peter Tewkesbury


Peter Tewkesbury

GeneralRe: Publish just the custom open file dialog
Jackey_shao
22:48 8 Aug '07  
Is there a chmReader that can run in wince.net 4.2 and Created for EVC4.0?Can be running on CPU type is arm4 or x86.
GeneralRe: Publish just the custom open file dialog
Peter Tewkesbury
0:33 9 Aug '07  
There is another CHMReader which is developed using C# for .NET V2 CF - http://www.codeproject.com/netcf/CHMReaderNet.asp[^]

This version should be more portable providing you can run .NET V2.0 CF on the device.

Big Grin

Peter Tewkesbury

GeneralRe: Publish just the custom open file dialog
Jackey_shao
0:48 9 Aug '07  
This version is running VS2003 or VS2005 IDE,and Im used EVC4.0,So can't run it!:(I need using it to opening chm type file on short time.Can you help me?
regard!
GeneralRe: Publish just the custom open file dialog
Peter Tewkesbury
4:22 9 Aug '07  
The .NET version of CHMReader on Codeproject has release cabs which can be installed on any Windows CE Mobile device which runs .NET V2 CF. You do not need this version.



Peter Tewkesbury

GeneralRe: Publish just the custom open file dialog
Jackey_shao
15:47 9 Aug '07  
First all thx your relay,but I'm install CHMReader.WCE420X86.CAB in wince4.2 of Emulator CPU x86:(,This was take place error:ArgumentOutOfRangeException took place error at Application::Run+0x1a CHMReader::Main+0xd5
"OK"should be stop
regards
QuestionDirectoryNotFoundException
Korayem.NET
0:42 5 Sep '06  
First, thank you for this great program. It's a time saver since now I can read through my books while I am on the bus each day going to and from my work place during the 1 hour trip.

I installed the latest version 2.0.14 from the cab files. I have a windows mobile 5.0 K-JAM. I tried installing to device and storage card but in vain Sigh . I always receive the following error whenever I choose "File" -> "Open":

CHMReader.NET V2.0.14 Exception Message:
DirectoryNotFoundException

I tried searching the comments of this article but it seems no one else had that problem.

BTW, I have installed .NET CF 2 SP1. And normally, .NET CF 1.0 is installed by default with all WM 5.0. So where is the problem??

Great program Rose that I badly need Big Grin

-- modified at 2:22 Thursday 7th September, 2006
AnswerRe: DirectoryNotFoundException
Korayem.NET
21:35 6 Sep '06  
Workaround to my problem: Instead of opening CHMReader.NET then from it try to open the desired chm file, I made the file type .chm associated with CHMReader.NET so that whenever I open a chm file from the file explorer, it would open it with CHMReader.NET and this works fine so far.


Thanks for the program, but I still wish to have my problem solved Smile
GeneralNotSupportedException
Sri harini
18:11 15 Aug '06  

public NewDBBroker(string Path)
{
FileInfo fi = new FileInfo(path);
if (!fi.Exists)
CreateDataBase(Path);
else
{
DBFile = Path;
// OpenDataBase();
}
}

Hi,

I tried the above code, NotSupportedException coming..
I am using SQLLite Database.
Anybody help me,


sarala


AnswerRe: NotSupportedException
Pedro Simao
6:34 23 Aug '06  
this as nothing to do with the CHMReader...

Yet... check CreateDataBase(); ...|| I think you're using it uncorrectly...
I don't even know if it exists, or wich namespace it's from
GeneralUnexpected error has occurred in chmreader.net.exe
GodlyDevil
18:19 13 Feb '06  
Hey Peter,
Thanks for your work on CHM Reader. I have been using the CHM reader 1.0 for a while now a I was upgrading to v2.06 and am getting this error on a Dell Axim with v1.0 sp3 and v2.0 of the .net compact framework installed.

"An unexpected error has occurred in CHMREader.Net.exe. Select Quit and then restart this program, or select details for more information." then when I select Details:

CHMReader.Net.EXE
IOException

Application::Run+0xf
CHMReader::Main+0xd5

Any clues. This happens when I tap File/Open. I don't even have a CHM file open yet. BTW got the same error message with only .net v1 sp1 and then upgraded to .net v1 sp3. Same error then upgraded to .net v2.

Hopefully all this helps track it down. I've tried looking at the source but I'm not fluent in C# yet on a PPC. Smile Thanks


-- modified at 23:35 Monday 13th February, 2006

Added...I just downloaded and installed v3.0.2147 of PPCHelpReader.net from www.blueflower.net and I get the same basic error when I tap File/Open: "PPCHelpReader.Net V3.0.2147 Exception Message : IOException" This is the Demo version.Confused
QuestionRe: Unexpected error has occurred in chmreader.net.exe
lsantillo
4:06 18 Feb '06  
Hi,

I get a different error, on a Dell Axim x51v (VGA). I can get to choose files to open, with CHMReader 2.0.5 (latest), but whichever file I choose, I get "PlatformNotSupportedException" + "Application::Run+0xf" + "CHMReader::Main+0xd5".

Any way to solve this and having CHMReader showing any CHM?

Thanks in advance Smile

L.
AnswerRe: Unexpected error has occurred in chmreader.net.exe
Grugnorr
2:59 3 Apr '06  
Ouch, I was going to try it on my new Axim51v just nowFrown
AnswerRe: Unexpected error has occurred in chmreader.net.exe
AlexNek
8:48 25 Jan '07  
it is unhandled exception in this line
DirectoryInfo[] Dirs = DI.GetDirectories();
I try to correct as
private void ExpandNode(TreeNodeCollection ParentNode, string RootDir)
{
DirectoryInfo DI=new DirectoryInfo(RootDir);
try
{
DirectoryInfo[] Dirs = DI.GetDirectories();

// Sort Dirs
ArrayList DirSorted = new ArrayList(Dirs.Length);
foreach (DirectoryInfo DI1 in Dirs)
{
DirSorted.Add(DI1);
}
DirSorted.Sort(new myDirSort());

foreach (DirectoryInfo DI2 in DirSorted)
{
TreeNode tn = new TreeNode(DI2.Name);
tn.Tag = DI2.FullName;
tn.ImageIndex = 6;
tn.SelectedImageIndex = 5;
ParentNode.Add(tn);
ExpandNode(tn.Nodes, DI2.FullName);
}
}
catch
{
}
}


AlexNek
QuestionRe: Unexpected error has occurred in chmreader.net.exe
snoopy99
9:15 31 Jul '07  
Hi Alex,

unfortunately I've got the same error - but I'm not able to compile a corrected version...
Can you post me your compiled version as *.cab for an arm processor?
Or can you publish it?

this would be great!!!
best regards, juergen.
GeneralRe: Unexpected error has occurred in chmreader.net.exe
Jackey_shao
16:17 9 Aug '07  
Im install CHMReader.WCE420X86.CAB in wince4.2 of Emulator CPU x86:(,This was take place error:ArgumentOutOfRangeException took place error at Application::Run+0x1a CHMReader::Main+0xd5
"OK"should be stop

Can you send me the correct versions?Thx.
Generalfonts
theGrim
10:41 12 Jan '06  
The .Net version is perfect. Thank you.
Just I'm wondering about changing default fonts.
When I see content tree, all fonts are smooth on Axim51v(640*480) screen, but fonts in actual document view screen are not good.
I'm c# developer and possible can fix it by myself if you point me to specific file or files related to help rendering.

Ps.
It forgets, how to change fonts to not a clear type.
GeneralRe: fonts
Peter Tewkesbury
23:41 13 Jan '06  
Hi

I use the Pocket IE control to display all HTML content in the CHMReader. The fonts that are used will be defined by the HTML content in the CHM files.



Peter Tewkesbury
Lead Developer


Last Updated 16 Aug 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010