16,548
社区成员




HINSTANCE hInst;
hInst = LoadLibrary("LZMA.dll");
typedef int (_stdcall *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 */
);
FuncCompress MyCompress = (FuncCompress)GetProcAddress(hInst, "LzmaCompress");
if(!MyCompress)
{
MessageBox("获取compress函数地址失败! ");
return;
}
unsigned int dlen = sizeof(m_ucdecompress); //m_ucdecompress 压缩后的数据存储区
size_t *destLen = &dlen; //认为压缩后的数据长度
const unsigned char srcarr[] = "12ac56";//hello hello hello world hello hello hello world
const unsigned char *src = srcarr;
size_t srcLen = sizeof(srcarr);
m_unCompressLen = srcLen; //要压缩的数据长度,在解压时做为解压后的数据长度
unsigned char outpprops[1024]; //这个参数不知什么作用,不知给什么值合适
unsigned char *outProps = outpprops;
unsigned int PropsSize = 5; //这个参数也不知什么作用,其值要求必须是 5
size_t *outPropsSize = &PropsSize; // outPropsSize must be = 5
int level = 5; // 0 <= level <= 9, default = 5
unsigned dictSize = 1 << 24; // default = (1 << 24) 16777216 1000000000000000000000000
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
int status = MyCompress(m_ucdecompress,
destLen,
src,
srcLen,
outProps,
outPropsSize,
level,
dictSize,
lc,
lp,
pb,
fb,
numThreads );
//解压部分不能解压正确 下面是解压部分
HINSTANCE hInst;
hInst = LoadLibrary("LZMA.dll");
typedef int (_stdcall *FuncUnCompress)(unsigned char *dest,
size_t *destLen,
const unsigned char *src,
size_t *srcLen,
const unsigned char *props,
size_t propsSize
);
FuncUnCompress MyUnCompress = (FuncUnCompress)GetProcAddress(hInst, "LzmaUncompress");
if(!MyUnCompress)
{
MessageBox("获取uncompress函数地址失败! ");
return;
}
unsigned char destarr[1024];
unsigned int dlen = m_unCompressLen; // 解压缩后的数据长度 即原文长度
unsigned char *dest = destarr;
size_t *destLen = &dlen;
size_t usrcLen = m_unDeCompressLen; //要解压数据长度
size_t *srcLen = &usrcLen;
const unsigned char outProps[12] = "12345678910"; //这个参数不知何用 也不知给值多少
size_t outPropsSize = 5; // outPropsSize must be = 5
int status = MyUnCompress(dest,
destLen,
m_ucdecompress, //解压数据
srcLen,
outProps,
outPropsSize
);