//--------------------------------------------------------------------------- #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 TPCompressM(BYTE **mh, BYTE *data, int length, TCompressMethod cm) { HINSTANCE hLibrary = NULL; TZLibCompress ZLibCompress; BYTE *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 ((*mh = (BYTE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ld+4))==NULL) goto fail; r = ZLibCompress(*mh+4, &ld, data, ls); if (r==0) break; HeapFree(GetProcessHeap(), 0, *mh); *mh = NULL; if (n==1) { ld = ls; break; } else n--; } } FreeLibrary(hLibrary); hLibrary = NULL; } if (ld