Home Forums ActiveX components Xceed Zip for ActiveX & x64 compress stream (char*) in VC++ & Decompress byte[] in .NET in memory

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #42454 |

    Hi Xceed Developers and Users.

    how can I compress a stream (char*) in VC++ &  Decompress byte[] in .NET? Both the compression & decompression need to be done in memory, no file handling is invoved.

    Can u suggest a way to do this? Some example code would be very much helpful.

    Thanks in advance!

    Imported from legacy forums. Posted by kaushik (had 2012 views)

    Xceed Support
    Post count: 5658

    Hi Kaushik,

    There is a sample application that is installed on your hard drive after installing the component. You can find it in its default location found here:

    C:\Xceed Samples\Xceed Zip Compression Library v6.5 (Samples)\Visual C++ 6-7\MemoryCompression

    As for decompression, you can follow here:

    Add a reference to XceedZip.dll to your .NET application.


    Your code could look like this:

    using XceedZipLib;

    static void Case149392()
      XceedCompression compression = new XceedCompressionClass();
      compression.License( LicenseKey );

      byte[] compressed = new byte[ size ];
      byte[] uncompressed;

      object inData, outData;

      xcdCompressionError result;

      // TODO: Fill the ‘compressed’ byte array with your compressed data that was created by
      // Xceed Zip ActiveX.
      // The ActiveX wrapper works best when object type variables are used when calling methods
      // with ‘ref’ or ‘out’
      inData = compressed;

      // Decompress the data. If not all the data is contained in ‘inData’, set the bEndOfData parameter
      // to ‘false’ and call Uncompress() again with more data until all the compressed data has been
      // passed to Uncompress()
      result = compression.Uncompress( ref inData, out outData, true );

      // The ActiveX wrapper works best when object type variables are used when calling methods
      // with ‘ref’ or ‘out’
      uncompressed = ( byte[] ) outData;

      // TODO: Do something with the uncompressed data. Save it to a file, process it, whatever.


    Any other information that you need can be found on our online documentation:


    Imported from legacy forums. Posted by Marc [Xceed] (had 224 views)

    User (Old forums)
    Post count: 23064

    Hi Marc,


    Thanks a lot for your reply.

    I checked the sample program suggested by you (C:\Xceed Samples\Xceed Zip Compression Library v6.5 (Samples)\Visual C++ 6-7\MemoryCompression); but this code is to compress memory stream in to a zip file in a physical location (e.g. test.zip in c:\temp\). My requirement is to compressing a memory stream buffer in  to a memory buffer, not in to a physical location.

    • I have written the following codes, Please find:

    for compression in ActiveX (VC++) side:

    VARIANT dataToCompress;
    VARIANT compressedData;
    VARIANT uncompressedData;
    SAFEARRAY * safeArray;
    BYTE * safeArrayData;
    size_t length;
    char * compressedDataStream;
    SAFEARRAY * arrayDescriptor;
    long lHigh =0;
    long lLow =0;
    IXceedCompressionPtr pCompression( CLSID_XceedCompression );
      if( pCompression->License( _bstr_t( L”License Code” ) ) == VARIANT_FALSE )

              return NULL;
          safeArray = SafeArrayCreateVector( VT_I1, 0, length );
          SafeArrayAccessData( safeArray, ( void ** ) &safeArrayData );
          CopyMemory( safeArrayData, strCompress, length );
          SafeArrayUnaccessData( safeArray );
          VariantInit( &dataToCompress );
          VariantInit( &compressedData );
          VariantInit( &uncompressedData );
          dataToCompress.vt = VT_ARRAY | VT_UI1;
          dataToCompress.parray = safeArray;
          xcdCompressionError error = pCompression->Compress( &dataToCompress, &compressedData, VARIANT_TRUE );
          VariantClear( &dataToCompress );
          if ( error != xceSuccess )
            throw new _com_error( error );
            SAFEARRAY *psa = compressedData.parray;
            LONG lSize = lHigh – lLow +1;
            Char *pcdata;
            char *pcNew = new char[lSize=1];
            pcNew[lSize] = 0;
            return CString( (char*)pcNew);

     In Decompression Side (C# .Net):

    XceedZipLib.XceedCompression compressor = new XceedZipLib.XceedCompressionClass();
    compressor.License(“Licensse Code”);
    object UncompressedData;
    XceedZipLib.xcdCompressionError xErr = compressor.Uncompress(arrImgFileData, out UncompressedData, true);
           if(UncompressedData != null)
               return (byte[])UncompressedData;
               return null;

    I am getting an error of “xceCompression
    while decompression.
    Is this above codes are fine or I need to change some where?

    •  I have written one more code for Compression (ActiveX VC++) using direct dll api:

       BYTE* pcCompressed = NULL;
       DWORD dwCompressedSize = 0;  
       DWORD dwSourceSize = iLen + 1;
       HMODULE m_hXceedZipDll = LoadLibraryA( “XceedZip.dll” );
        if( m_hXceedZipDll  != NULL)
              XceedZipFunctions *pFuncs  = ( XceedZipFunctions *) GetProcAddress( m_hXceedZipDll, “g_xzFunctions” );
            if( pFuncs )
                HXCEEDZIP hComp  = pFuncs->lpfnXzCreateXceedZipA(“License code” );
                if (!hComp )
                    return NULL;
                pFuncs->lpfnXcSetCompressionLevel( hComp, xclHigh );
                pFuncs->lpfnXcCompress(hComp,(BYTE*)strCompress,dwSourceSize, &pcCompressed, &dwCompressedSize, TRUE);
                return CString((char*)pcCompressed);

    Please let me know how to proceed in Decompression side of C# .Net in response of above compression code (direct dll api)?

    • Regarding Compression at Activex (VC++) side & Decompression at C# .Net side of a stream/buffer; both in a memory  (not in to a physical location, no physical file need to be created) what is the best library to be used, “Streaming Compression” or “Zip Compression” ? Compression will be done at client PC (32/64 bit machine) and Decompression will be done at server side (32 bit server).

    Thanks in advance!

    Imported from legacy forums. Posted by kaushik (had 271 views)

    User (Old forums)
    Post count: 23064
    • My Current Status with ZipCompression:

    1. I Could able to Compress at Client side in Activex (VC++) and could able to convert the compressed variant to char* array

    2.  used the compressed char* array of stream, converted to variant and could able to decompressed at Client side in Activex (VC++).

    3. While decompressing at server side in C# .Net getting error of “xceCompression

    4. I have used the normal compress api, not the direct dll api.

    Thanks in advance!

    Imported from legacy forums. Posted by kaushik (had 1824 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.