//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Compress.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- typedef int WINAPI (*TZLibCompress)(void *dest, DWORD *destLen, const void *source, DWORD sourceLen); typedef int WINAPI (*TZLibUncompress)(void *dest, DWORD *destLen, const void *source, DWORD sourceLen); //--------------------------------------------------------------------------- bool __fastcall TPCompress(HANDLE fh, void *data, int length, TCompressMethod cm) { DWORD dwWrite; HINSTANCE hLibrary = NULL; TZLibCompress ZLibCompress; void *dst = NULL; DWORD ls, ld; int n, r; switch (cm) { case cmZLib: ld = ls = length; hLibrary = LoadLibrary("zlib.dll"); if (hLibrary) { ZLibCompress = (TZLibCompress)GetProcAddress(hLibrary, "compress"); if (ZLibCompress) { n = 4; while (1) { ld = ls/n; if ((dst = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ld))==NULL) goto fail; r = ZLibCompress(dst, &ld, data, ls); if (r==0) break; HeapFree(GetProcessHeap(), 0, dst); dst = NULL; if (n==1) { ld = ls; break; } else n--; } } FreeLibrary(hLibrary); hLibrary = NULL; } if (ld