⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gzipfile.c

📁 是一个C语言的压缩和解压缩的DLL源程序.
💻 C
字号:
#include <windows.h>
#include <tchar.h>

// Include LiteZip.h for creating a ZIP archive
#include "../LiteZip.h"





// Where we store the pointers to LiteZip.dll's functions that we call
ZipCreateFilePtr		*lpZipCreateFile;
ZipAddFilePtr			*lpZipAddFile;
ZipClosePtr				*lpZipClose;
ZipFormatMessagePtr		*lpZipFormatMessage;
ZipOptionsPtr			*lpZipOptions;





/*********************** show_errmsg() **********************
 * Displays a messagebox for the passed OS error number.
 */

void show_errmsg(void)
{
	TCHAR buffer[160];

	buffer[0] = 0;
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &buffer[0], 160, 0);
	MessageBox(0, &buffer[0], _T("Error"), MB_OK);
}





/************************** main() *************************
 * Program entry point.
 */

int main()
{
	HMODULE		zipDll;
	HZIP		hz;
	DWORD		result;

	// Open the LiteZip.DLL. Note: If LiteZip.dll is not placed in a path that can be found
	// by this app, then LoadLibrary will fail. So, either copy LiteZip.dll to the same
	// directory as this EXE, or to some directory that Windows is set to search.
	if ((zipDll = (HMODULE)LoadLibrary(_T("../LiteZip.dll"))))
	{
		// Get the addresses of 5 functions in LiteZip.dll -- ZipCreateFile(), ZipAddFile()
		// ZipClose(), ZipFormatMessage, and ZipOptions
		lpZipCreateFile = (ZipCreateFilePtr *)GetProcAddress(zipDll, ZIPCREATEFILENAME);
		lpZipAddFile = (ZipAddFilePtr *)GetProcAddress(zipDll, ZIPADDFILENAME);
		lpZipClose = (ZipClosePtr *)GetProcAddress(zipDll, ZIPCLOSENAME);
		lpZipFormatMessage = (ZipFormatMessagePtr *)GetProcAddress(zipDll, ZIPFORMATMESSAGENAME);
		lpZipOptions = (ZipOptionsPtr *)GetProcAddress(zipDll, ZIPOPTIONSNAME);

		// Create a ZIP archive on disk named "test.gzip"
		if (!(result = lpZipCreateFile(&hz, _T("test.gzip"), 0)))
		{
			// Set the option to make it a GZIP (instead of PkZip) format archive. This must
			// be done before adding any file to it
			if ((result = lpZipOptions(hz, TZIP_OPTION_GZIP)) ||

				// Add the file "test.jpg" to the GZIP, and give it the same name inside the GZIP
				(result = lpZipAddFile(hz, _T("test.jpg"), _T("test.jpg"))))
			{
				lpZipClose(hz);
				goto bad;
			}

			// Done adding the file, so close the GZIP archive
			lpZipClose(hz);
		}
		else
		{
			TCHAR	msg[100];

bad:		lpZipFormatMessage(result, msg, sizeof(msg));
			MessageBox(0, &msg[0], _T("Error"), MB_OK);
		}

		// Free the LiteZip.DLL
		FreeLibrary(zipDll);
	}
	else
		show_errmsg();

	return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -