File compression and decompression in Windows Mobile

Source: Internet
Author: User
Tags gz file

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.

 

Related Article

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.