zlib在windows上的编译

来源:互联网 发布:python列表推导式 编辑:程序博客网 时间:2024/06/06 19:28

from:

http://blog.sina.com.cn/s/blog_96ea53fb0101ldd9.html

http://blog.csdn.net/yuzhiyuxia/article/details/25826639

http://blog.csdn.net/htttw/article/details/7616124

 

首先从http://www.zlib.net/下载了最新的源代码,版本是1.2.8

解压后,实际已经提供了在VC下编译的工程,目录为:
zlib-1.2.8\contrib\vstudio
其中只有vc9和vc10
编译

直接使用其库,下载zlib128-dll,里面有.LIB, .DLL,  .H文件

导入到自己的工程

//解压文件

  CFile bmpFile(_T("C:\\dh_255.bmp"), CFile::modeRead|CFile::typeBinary);
 unsigned long lSize = bmpFile.GetLength();
 CString strSize;
 strSize.Format(_T("%8x"), lSize);  // 文件大小
 unsigned long lSizeDest = lSize;
 if (lSize > 0)
 {
  BYTE* pBufSrc = new BYTE[lSize];
  memset(pBufSrc, 0, lSize);
  BYTE* pBufDest = new BYTE[lSizeDest];
  memset(pBufDest, 0, lSizeDest);
  bmpFile.Read(pBufSrc, lSize);
  
  INT_PTR iComp = compress(pBufDest, &lSizeDest, pBufSrc, lSize);
  CFile zipFile(_T("C:\\dh_255.zip"), CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
  std::string str;
  WCToStr(strSize, str);
  zipFile.Write(str.c_str(), strSize.GetLength() + 1);// 存储解压之后的文件大小
  zipFile.Seek(9+1, CFile::begin);
  zipFile.Write(pBufDest, lSizeDest);
  delete [] pBufDest;
  pBufDest = NULL;
  delete [] pBufSrc;
  pBufSrc = NULL;
  zipFile.Close();
 }
 bmpFile.Close();
 ///* 解压缩 */ 
 CFile zipFile(_T("C:\\dh_255.zip"), CFile::modeRead|CFile::typeBinary);
 unsigned long lZipSrc = zipFile.GetLength();
 unsigned long lZipDest = lSize+ 10;
 BYTE* pBufZip = new BYTE[lZipSrc];
 
 BYTE* pBufSize = new BYTE[9];
 memset(pBufZip, 0, lZipSrc);

 memset(pBufSize, 0, 9);
 zipFile.Read(pBufSize, 9);//////读取 解压之后的文件大小
 unsigned long lSizenew = strtoul((const char*)pBufSize, 0, 16);
 BYTE* pBufBmp = new BYTE[lSizenew];
 memset(pBufBmp, 0, lSizenew);
 zipFile.Seek(9+1, CFile::begin);
 zipFile.Read(pBufZip, lZipSrc);
 
 INT_PTR iUnComp = uncompress(pBufBmp, &lSizenew, pBufZip, lZipSrc);
 CFile destBmpFile(_T("C:\\dh_2550.bmp"), CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
 destBmpFile.Write(pBufBmp, lSizenew);
 delete [] pBufZip;
 pBufZip = NULL;
 zipFile.Close();
 destBmpFile.Close(); 

//压缩数据

 //* 原始数据 */  
 unsigned char strSrc[] = "hello world! aaaaa bbbbb ccccc ddddd 中文测试 yes";  
 unsigned char buf[1024] = {0};  
 unsigned char strDst[1024] = {0};  
 unsigned long srcLen = sizeof(strSrc);  
 unsigned long bufLen = sizeof(buf);  
 unsigned long dstLen = sizeof(strDst); 


 //* 压缩 */  
 compress(buf, &bufLen, strSrc, srcLen); 
 //

 //* 解压缩 */  
 uncompress(strDst, &dstLen, buf, bufLen);
 //* 压缩 */

 

0 0