我现在想使用 LZMA 压缩算法中的 LZMA.dll ,但总是调试不出来,谁有如何测试使用 LZMA.dll的 VC 测试程序,发一下呀,特别感谢。就是如何调用使用这两个函数呀。
EXPORTS
LzmaCompress
LzmaUncompress
EXPORTS
LzmaCompress
LzmaUncompress
解决方案 »
- CListCtrl 的SetCapture无效的问题
- 网上下载的ie BHO程序,为啥调试就是进不来呢?
- 初学,关于MFC的OnLButton事件
- 关于socket模型的事件选择模型中的一句话的理解
- dll
- 有难度的SQL语句,类似高级语言的setch...case,在线求解.
- 大虾们快来看:像这种SQL语句如何在Command里执行?
- 问高手一个问题,有关黑白图的数据采集
- 请问应该如何设定CPropertySheet中PropertyPage的尺寸?
- 容易的问题(位图)
- VC2010如何操作数据库呢
- 我写了一个http的代理客户端,经测试没问题了,现在想做https的,不知道有什么区别?请知道的进来指点一下。
看看有没有你要的
一个lib,一个dll,里面因为还有zlib,和其他一些压缩解压函数,所以有点大。
Byte *destBuf=new Byte[destBufLen];
SizeT srcLen=packet->length;
SRes ret=Lzma86_Decode(destBuf,&destBufLen,(const Byte *)packet->data,&srcLen);
我用的是Lzma86_Decode,这是解压部分,压缩部分也差不多。
hInst = LoadLibrary("LZMA.dll");
// LzmaCompress
// LzmaUncompress
typedef int (*FuncCompress)(unsigned char *dest,
size_t *destLen,
const unsigned char *src,
size_t srcLen,
unsigned char *outProps,
size_t *outPropsSize, /* *outPropsSize must be = 5 */
int level, /* 0 <= level <= 9, default = 5 */
unsigned dictSize, /* default = (1 << 24) */
int lc, /* 0 <= lc <= 8, default = 3 */
int lp, /* 0 <= lp <= 4, default = 0 */
int pb, /* 0 <= pb <= 4, default = 2 */
int fb, /* 5 <= fb <= 273, default = 32 */
int numThreads /* 1 or 2, default = 2 */
);
typedef int (*FuncUnCompress)(unsigned char *dest,
size_t *destLen,
const unsigned char *src,
size_t *srcLen,
const unsigned char *props,
size_t propsSize); FuncCompress MyCompress = (FuncCompress)GetProcAddress(hInst, "LzmaCompress");
FuncUnCompress MyUnCompress = (FuncUnCompress)GetProcAddress(hInst, "LzmaUncompress");
if(!MyCompress)
{
MessageBox("获取函数地址失败! ");
return;
}
if(!MyUnCompress)
{
MessageBox("获取uncompress函数地址失败! ");
return;
} const unsigned char srcarr[] = "hello hello world";
unsigned int PropsSize = 5; unsigned char outpprops[] = "abcde"; unsigned char *dest;
size_t *destLen;
const unsigned char *src = srcarr;
size_t srcLen = 18;
unsigned char *outProps = outpprops;
size_t *outPropsSize = &PropsSize; // outPropsSize must be = 5
int level = 5; // 0 <= level <= 9, default = 5
unsigned dictSize = 1; // default = (1 << 24)
int lc = 3; // 0 <= lc <= 8, default = 3
int lp = 0; // 0 <= lp <= 4, default = 0
int pb = 2; // 0 <= pb <= 4, default = 2
int fb = 32; // 5 <= fb <= 273, default = 32
int numThreads = 2; // 1 or 2, default = 2
MyCompress(dest, destLen, src, srcLen,outProps, outPropsSize, level, dictSize, lc, lp, pb, fb, numThreads );//在这些出错了。#define MY_STDAPI MY_EXTERN_C int MY_STD_CALLLzmaCompress
------------outPropsSize -
In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. LZMA Encoder will use defult values for any parameter, if it is
-1 for any from: level, loc, lp, pb, fb, numThreads
0 for dictSize
level - compression level: 0 <= level <= 9; level dictSize algo fb
0: 16 KB 0 32
1: 64 KB 0 32
2: 256 KB 0 32
3: 1 MB 0 32
4: 4 MB 0 32
5: 16 MB 1 32
6: 32 MB 1 32
7+: 64 MB 1 64
The default value for "level" is 5. algo = 0 means fast method
algo = 1 means normal methoddictSize - The dictionary size in bytes. The maximum value is
128 MB = (1 << 27) bytes for 32-bit version
1 GB = (1 << 30) bytes for 64-bit version
The default value is 16 MB = (1 << 24) bytes.
It's recommended to use the dictionary that is larger than 4 KB and
that can be calculated as (1 << N) or (3 << N) sizes.lc - The number of literal context bits (high bits of previous literal).
It can be in the range from 0 to 8. The default value is 3.
Sometimes lc=4 gives the gain for big files.lp - The number of literal pos bits (low bits of current position for literals).
It can be in the range from 0 to 4. The default value is 0.
The lp switch is intended for periodical data when the period is equal to 2^lp.
For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
better to set lc=0, if you change lp switch.pb - The number of pos bits (low bits of current position).
It can be in the range from 0 to 4. The default value is 2.
The pb switch is intended for periodical data when the period is equal 2^pb.fb - Word size (the number of fast bytes).
It can be in the range from 5 to 273. The default value is 32.
Usually, a big number gives a little bit better compression ratio and
slower compression process.numThreads - The number of thereads. 1 or 2. The default value is 2.
Fast mode (algo = 0) can use only 1 thread.Out:
destLen - processed output size
Returns:
SZ_OK - OK
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater
SZ_ERROR_OUTPUT_EOF - output buffer overflow
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
int level, /* 0 <= level <= 9, default = 5 */
unsigned dictSize, /* default = (1 << 24) */
int lc, /* 0 <= lc <= 8, default = 3 */
int lp, /* 0 <= lp <= 4, default = 0 */
int pb, /* 0 <= pb <= 4, default = 2 */
int fb, /* 5 <= fb <= 273, default = 32 */
int numThreads /* 1 or 2, default = 2 */
);/*
LzmaUncompress
--------------
In:
dest - output data
destLen - output data size
src - input data
srcLen - input data size
Out:
destLen - processed output size
srcLen - processed input size
Returns:
SZ_OK - OK
SZ_ERROR_DATA - Data error
SZ_ERROR_MEM - Memory allocation arror
SZ_ERROR_UNSUPPORTED - Unsupported properties
SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
*/MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
const unsigned char *props, size_t propsSize);
size_t *destLen,
const unsigned char *src,
size_t srcLen,
unsigned char *outProps,
size_t *outPropsSize, /* *outPropsSize must be = 5 */
int level, /* 0 <= level <= 9, default = 5 */
unsigned dictSize, /* default = (1 << 24) */
int lc, /* 0 <= lc <= 8, default = 3 */
int lp, /* 0 <= lp <= 4, default = 0 */
int pb, /* 0 <= pb <= 4, default = 2 */
int fb, /* 5 <= fb <= 273, default = 32 */
int numThreads /* 1 or 2, default = 2 */
);
压缩:
compress2(dstbuffer, &streamlen, buffer, buffersize, Z_BEST_COMPRESSION);
看下定义:
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
当然也可以使用compress,定义如下:
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));解压缩uncompress,看定义:
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));