#include "stdafx.h"
#include<windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <direct.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#define PATH_MAX 128
//Îïðåäåëÿåì ñòðóêòóðû
typedef int (WINAPI DLLPRNT) (LPSTR, unsigned long);
typedef int (WINAPI DLLPASSWORD) (LPSTR, int, LPCSTR, LPCSTR);
typedef int (WINAPI DLLSERVICE) (LPCSTR, unsigned long);
typedef int (WINAPI DLLCOMMENT) (LPSTR);
void strucase(char *str);
typedef struct {
int argc; // Count of files to zip
LPSTR lpszZipFN; //Archive file name
char **FNV; // file names to zip up. Think of this an argv
} ZCL, *LPZCL;
typedef struct {
LPSTR Date; /* Date to include after */
LPSTR szRootDir; /* Directory to use as base for zipping */
LPSTR szTempDir; /* Temporary directory used during zipping */
BOOL fTemp; /* Use temporary directory '-b' during zipping */
BOOL fSuffix; /* include suffixes (not implemented in WiZ) */
BOOL fEncrypt; /* encrypt files */
BOOL fSystem; /* include system and hidden files */
BOOL fVolume; /* Include volume label */
BOOL fExtra; /* Exclude extra attributes */
BOOL fNoDirEntries; /* Do not add directory entries */
BOOL fExcludeDate; /* Exclude files earlier than specified date */
BOOL fIncludeDate; /* Include only files earlier than specified date */
BOOL fVerbose; /* Mention oddities in zip file structure */
BOOL fQuiet; /* Quiet operation */
BOOL fCRLF_LF; /* Translate CR/LF to LF */
BOOL fLF_CRLF; /* Translate LF to CR/LF */
BOOL fJunkDir; /* Junk directory names */
BOOL fGrow; /* Allow appending to a zip file */
BOOL fForce; /* Make entries using DOS names (k for Katz) */
BOOL fMove; /* Delete files added or updated in zip file */
BOOL fDeleteEntries; /* Delete files from zip file */
BOOL fUpdate; /* Update zip file--overwrite only if newer */
BOOL fFreshen; /* Freshen zip file--overwrite only */
BOOL fJunkSFX; /* Junk SFX prefix */
BOOL fLatestTime; /* Set zip file time to time of latest file in it */
BOOL fComment; /* Put comment in zip file */
BOOL fOffsets; /* Update archive offsets for SFX files */
BOOL fPrivilege; /* Use privileges (WIN32 only) */
BOOL fEncryption; /* TRUE if encryption supported, else FALSE.
this is a read-only flag */
int fRecurse; /* Recurse into subdirectories. 1 => -r, 2 => -R */
int fRepair; /* Repair archive. 1 => -F, 2 => -FF */
char fLevel; /* Compression level (0 - 9) */
} ZPOPT, *LPZPOPT;
typedef struct {
DLLPRNT *print; // pointer to application's print function.
DLLCOMMENT *comment; // pointer to application's function for processing
// comments.
DLLPASSWORD *password; // pointer to application's function for processing
//passwords.
DLLSERVICE *ServiceApplication; // Optional callback function for processing
// messages, relaying information.
} ZIPUSERFUNCTIONS, * LPZIPUSERFUNCTIONS;
typedef int (WINAPI * _DLL_ZIP)(ZCL);
typedef int (WINAPI * _ZIP_USER_FUNCTIONS)(LPZIPUSERFUNCTIONS);
typedef BOOL (WINAPI * ZIPSETOPTIONS)(LPZPOPT);
ZCL ZpZCL;
LPZIPUSERFUNCTIONS lpZipUserFunctions;
_DLL_ZIP ZipArchive;
_ZIP_USER_FUNCTIONS ZipInit;
ZIPSETOPTIONS ZipSetOptions;
ZPOPT ZpOpt;
HANDLE hZuf=(HANDLE)NULL;
HMODULE hZipDll;
LPSTR;
char name[20];
char *flist[1];
char **index, *sz;
int retcode, i, cc;
int main(int argc, char* argv[])
{
lpZipUserFunctions=(LPZIPUSERFUNCTIONS)malloc((DWORD)sizeof(ZIPUSERFUNCTIONS));
//
hZipDll=LoadLibrary("D:\\zip32.dll");
if (hZipDll==NULL)
{
return 0;
}
(_DLL_ZIP)ZipArchive=(_DLL_ZIP)GetProcAddress(hZipDll,"ZpArchive");
if(!ZipArchive)
{
MessageBox(NULL,"Error","Error",MB_OK);
FreeLibrary(hZipDll);
return 0;
}
(ZIPSETOPTIONS)ZipSetOptions=(ZIPSETOPTIONS)GetProcAddress(hZipDll,"ZpSetOptions");
if(!ZipSetOptions)
{
MessageBox(NULL,"Error","Error",MB_OK);
FreeLibrary(hZipDll);
return 0;
}
(_ZIP_USER_FUNCTIONS)ZipInit=(_ZIP_USER_FUNCTIONS)GetProcAddress(hZipDll,"ZpInit");
if(!ZipInit)
{
MessageBox(NULL,"Error","Error",MB_OK);
FreeLibrary(hZipDll);
return 0;
}
if(!(*ZipInit)(lpZipUserFunctions))
{
free(lpZipUserFunctions);
FreeLibrary(hZipDll);
MessageBox(NULL,"Application functions not set up properly. Terminating...","Îøèáêà",MB_OK);
return 0;
}
memset(&ZpOpt,'\0',sizeof(ZPOPT));
ZpOpt.fSuffix=FALSE;
ZpOpt.fEncrypt=TRUE;
ZpOpt.fSuffix=FALSE;
ZpOpt.fVolume=FALSE;
ZpOpt.fExtra=FALSE;
ZpOpt.fNoDirEntries=FALSE;
ZpOpt.fVerbose=FALSE;
ZpOpt.fQuiet=TRUE;
ZpOpt.fCRLF_LF=FALSE;
ZpOpt.fLF_CRLF=FALSE;
ZpOpt.fJunkDir=TRUE;
ZpOpt.fGrow=TRUE;
ZpOpt.fForce=TRUE;
ZpOpt.fMove=TRUE;
ZpOpt.fDeleteEntries=FALSE;
ZpOpt.fUpdate=TRUE;
ZpOpt.fFreshen=FALSE;
ZpOpt.fJunkDir=FALSE;
ZpOpt.fLatestTime=FALSE;
ZpOpt.fComment=FALSE;
ZpOpt.fOffsets=FALSE;
//ZpOpt.fPrivilege=FALSE;
//ZpOpt.fEncryption=FALSE;
ZpOpt.Date=NULL;
ZpOpt.fRecurse=0;
ZpOpt.fRepair=0;
//ZpOpt.fLevel='9';
//getcwd(ZpOpt.szRootDir,PATH_MAX);
ZpOpt.szRootDir="D:\\test";
//ZpOpt.szTempDir="D:\\work";
ZpOpt.fTemp=FALSE;
//
ZpZCL.argc=1;
ZpZCL.lpszZipFN="test.zip";
char *file;
char fname[20];
char *flist[1];
file=(char*)malloc(lstrlen("D:\\itog_3.doc"));
lstrcpy(file,"D:\\itog_3.doc");
lstrcpy(fname,file);
strucase(fname);
flist[0]=fname;
ZpZCL.FNV=flist;
if(!ZipSetOptions(&ZpOpt))
{
free(lpZipUserFunctions);
//free(szFileList);
FreeLibrary(hZipDll);
MessageBox(NULL,"Неудалось установить опции архивирования","Ошибка",MB_OK);
return 0;
}
try{
retcode=ZipArchive(ZpZCL);
}
catch(...)
{
//free(szFileList);
free(lpZipUserFunctions);
FreeLibrary(hZipDll);
return 0;
}
if(retcode==0)
{
MessageBox(NULL,"Неполучилось создать архив","Ошибка",MB_OK);
}
else {
MessageBox(NULL,"Все OK","OK",MB_OK);
}
//free(szFileList);
free(lpZipUserFunctions);
FreeLibrary(hZipDll);
return 0;
}
void strucase(char *str)
{
char *ptr = str;
while(*ptr != '\0')
{
if (*ptr >= 'a' && *ptr <= 'z')
*ptr = toupper(*ptr);
ptr++;
}
}
zip32.dll Access Violation
First-chance exception in ZpTest2.exe: 0xC0000005: Access Violation.
Даже не знаю с чем это связано... Подскажите пожалуйста как это исправить
Вот исходный код:
Код: