艾莉丝.弗罗拉莉cg:在VC++中使用Zlib123库的方法

来源:百度文库 编辑:九乡新闻网 时间:2024/04/30 19:05:57

0、首先到网站"www.zlib.net"上下载个ZLIB源代码包,位置如下。The current release is publicly available here:zlib source code, version 1.2.3, zipfile format (570K, MD5 checksum abbd0f2b456206da5e3ffd1

1、首先到网站"www.zlib.net"上下载个ZLIB源代码包,位置如下。
The current release is publicly available here:
zlib source code, version 1.2.3, zipfile format (570K, MD5 checksum abbd0f2b456206da5e3ffd179324413a):
US (www.zlib.net) <- 这个是官方的下载地址,默认可以下载这个。
France (www.gzip.org)
Pick a mirror (prdownloads.sourceforge.net)

2、把下载完的"zlib123.zip"包解压缩后,使用VC++编译器打开"\zlib123\projects\visualc6\zlib.dsw"。

3、使用VC++编译器打开"zlib.dsw"以后,选择"Win32 LIB Release",并按快捷键[F7]来编绎生成"zlib.lib"。

4、如需使用时,把以下3个文件拷贝到自己的工程目录下。
"\zlib123\projects\visualc6\Win32_LIB_Release\zlib.lib"
"\zlib123\zlib.h"
"\zlib123\zconf.h"

5、简单的调用例子:
#include "zlib.h"
#pragma comment(lib, "zlib.lib")

void CZlibTestDlg::OnOK()
{
CString strc,strc2,strc3;
const unsigned char strSrc[] = "English test中文测试";
unsigned char buff[1024] = {0},strDst[1024] = {0};
unsigned long srcLen = sizeof(strSrc),bufLen = sizeof(buff),dstLen = sizeof(strDst);

strc.Format("Src string:%sLength:%d===================", strSrc, srcLen);

//压缩
compress(buff, &bufLen, strSrc, srcLen);
strc2.Format("After Compressed Length:%dCompressed String:%s==============", bufLen, buff);

//解压缩
uncompress(strDst, &dstLen, buff, bufLen);
strc3.Format("After UnCompressed Length:%dUnCompressed String:%s", dstLen, strDst);

AfxMessageBox(strc + strc2 + strc3);
}