Zlib is a function library for data compression and is widely used in Windows and Linux. Of course, this function library can also be used smoothly on Windows Mobile.
First go to the following address to download a package, especially for the wince system: http://www.tenik.co.jp /~ Adachi/wince/zlibce/index.html. Download has three items. If you do not want to go deep into the source code, select zlib for WindowsCE ver.1.1.4 (with binaries ).
After downloading it to the local device, unbind it. In the zlibce directory, the header files zconf. h and zlib. h are available. As for the library files, zlibce. Lib is under zlibce/wce400/armv4i.
Create a test project under vs2005 (ecv4.0 can of course) and add the above header files and library files to the project.
Add the following code as needed:
# Include "zlib. H"
# Pragma comment (Lib, "zlibce. lib ")
Now we can use the zlib library.
If pbuf needs to compress a piece of data and the data length is nlen, use the following code:
Gzfile zipfile = gzopen ("// program files // test.gz", "WB ");
Gzwrite (zipfile, (voidp) pbuf, nlen );
Gzclose (zipfile );
It seems quite simple. Note: The first parameter of gzopen is the const char * type, which is different from the file path parameter type in wince. If the pbuf type is char *, nlen should never use strlen () or anything. As for the reason, just...
After the compression is successful, we can see how to decompress the test.gz file:
Gzfile unzip = gzopen ("// program files // test.gz", "rb ");
Handle hfile = createfile (L "// program files // test. dat ",
Generic_write,
0,
Null,
Open_always,
File_attribute_normal,
Null
);
If (hfile! = Invalid_handle_value)
{
DWORD dw;
Byte pbuf [1000];
Int nlen;
While (true)
{
Nlen = gzread (unzip, (voidp) pbuf, 1000 );
If (nlen = 0)
{
Break;
}
Writefile (hfile, pbuf, nlen, & DW, null );
}
Gzclose (unzip );
Closehandle (hfile );
}
For usage of other functions, see zlib. h.