//依赖头文件
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <exception>
//定义函数指针
//typedef int(WINAPI*S_dll_callback_demo1)(unsigned char*,unsigned char*);
typedef int(WINAPI*ZipRead)(const char*, char*, char*, char*);
typedef int(WINAPI*ZipReadFileList)(const char*, char*, char**);
typedef int(WINAPI*ZipWrite)(const char*, char*, char*,int);
typedef int(WINAPI* ZipWriteBuffter)(const char* , char *, char*, char* , unsigned int , int );
typedef int(WINAPI* ZipReadBuffer)(const char* , char *, char *, char *, unsigned int* );
typedef int(WINAPI* ZipReadBufferSize)(const char* , char *, char *);
//定义API函数变量
static ZipWrite zipWriteFile;
static ZipRead zipReadFile;
static ZipReadFileList readList;
static ZipWriteBuffter zipWriteBuffter;
static ZipReadBuffer zipReadBuffter;
static ZipReadBufferSize zipReadBuffterSize;
int main(){
int i = 0;
int j = 0;
int malloclen = 0;
unsigned int len = 0;
char* dataout = NULL;
char* passwd = "123456";
int filenum = 0;
char filelist[256][256] = { 0x00 };
char data[] = "hello zip!";
char path[] = "D:\\D-Pro\\Test\\libzip\\Release\\libzip.dll";
HMODULE hDll = LoadLibrary(path);
if (hDll != NULL) {
zipWriteFile = (ZipWrite)GetProcAddress(hDll, "PackFile");
zipReadFile = (ZipRead)GetProcAddress(hDll, "UnpackFile");
readList = (ZipReadFileList)GetProcAddress(hDll, "UnpackFileList");
zipWriteBuffter = (ZipWriteBuffter)GetProcAddress(hDll, "PackBuffer");
zipReadBuffter = (ZipReadBuffer)GetProcAddress(hDll, "UnpackBuffer");
zipReadBuffterSize = (ZipReadBufferSize)GetProcAddress(hDll, "UnpackBufferSize");
/*if (zipWriteFile) {
zipWriteFile(passwd, "2.zip", "D:\\D-Pro\\Test\\test_zip\\test_zip\\test.S19",0);
}
else {
printf("\nZipWriteFile\n");
}
if (zipReadFile) {
zipReadFile(passwd, "2.zip", "test.S19",".//test//11111.s19");
}
else {
printf("\nZipReadFile\n");
}*/
if (zipWriteBuffter) {
zipWriteBuffter(passwd, "3.zip", "11112.txt", data, sizeof(data), 2);
}
else {
printf("\nzipWriteBuffter \n");
}
if (zipReadBuffter) {
if (zipReadBuffterSize) {
malloclen = zipReadBuffterSize(passwd, "3.zip", "11112.txt");
if (malloclen) {
dataout = (char*)malloc(malloclen + 8);
zipReadBuffter(passwd, "3.zip", "11112.txt", dataout, &len);
printf("%s\n", dataout);
if (dataout != NULL) {
free(dataout);
dataout = NULL;
}
}
}
}
else {
printf("\nzipWriteBuffter \n");
}
}
else
{
printf("\n加载失败!\n");
}
printf("\n请按任意键结束!\n");
_getch();
return 0;
}