0

I am using Xceedzip.dll COM Component 4.2 for in-memory compression (and I am referring to this documentation).

public void compressionCode(const char *loginRequestData) {
        XceedCompression ^compression = gcnew XceedCompressionClass();
            compression->License("My License Key!");

            xcdCompressionError r_error;
            VARIANT r_dataToCompress;
            VARIANT r_compressedData;
            VARIANT r_uncompressedData;
            SAFEARRAY *r_safeArray;
            char *r_safeArrayData;
            size_t r_length;

            r_length = strlen(loginRequestData);
            r_safeArray = SafeArrayCreateVector(VT_I1, 0, r_length);

            SafeArrayAccessData(r_safeArray, (void**)&r_safeArrayData);
            CopyMemory(r_safeArrayData, loginRequestData, r_length);
            SafeArrayUnaccessData(r_safeArray);

            VariantInit(&r_dataToCompress);
            VariantInit(&r_compressedData);
            VariantInit(&r_uncompressedData);

            r_dataToCompress.vt = VT_ARRAY | VT_I1;
            r_dataToCompress.parray = r_safeArray;

            //r_compressedData.vt = VT_ARRAY | VT_I1;
            //r_compressedData.parray = r_safeArray;

            IntPtr r_intPtrDataToCompress = (IntPtr)&r_dataToCompress;
            Object ^r_dataToCompressObject = Marshal::GetObjectForNativeVariant(r_intPtrDataToCompress);

            IntPtr r_intPtrCompressedData = (IntPtr)&r_compressedData;
            Object ^r_CompressedDataObject = Marshal::GetObjectForNativeVariant(r_intPtrCompressedData);

            r_error = compression->Compress(r_dataToCompressObject, r_CompressedDataObject, VARIANT_TRUE);
            //VariantClear(&r_dataToCompress);
            if (r_error != xcdCompressionError::xceSuccess)
                Console::WriteLine("Error Encountered!");

            if (r_CompressedDataObject != NULL) {
                PrintByteArrayVariant< unsigned char >(&r_compressedData);

            } else {
                Console::WriteLine("compressed Data Object NULL !");
            }}
    template< class DataType > static void PrintByteArrayVariant(VARIANT * variant) {
        DataType * data;
        SAFEARRAY * arrayDescriptor;
        int i, count;

        // Get the array descriptor from the variant
        arrayDescriptor = variant->parray;

        // Gain access to the array data
        SafeArrayAccessData(arrayDescriptor, (void **)&data);

        // Get the number of elements in the first dimension of the array
        count = arrayDescriptor->rgsabound[0].cElements / sizeof(DataType);

        int lineThreshold = 32 / sizeof(DataType);
        int groupThreshold = 4 / sizeof(DataType);
        char buffer[16];

        sprintf(buffer, "%%0%dX", sizeof(DataType) * 2);

        for (i = 0; i < count; i++)
        {
            // If we need to change line
            if ((i % lineThreshold) == 0 && i > 0)
                printf("\n");

            // If we need to seperate a group of data
            if ((i % groupThreshold) == 0)
                printf(" ");

            // Access the current index as we would a normal array
            printf(buffer, data[i]);
        }

        // Release access to the array data
        SafeArrayUnaccessData(arrayDescriptor);
    }

public void compressionCode(const char *loginRequestData) {
        XceedCompression ^compression = gcnew XceedCompressionClass();
            compression->License("My License Key!");

            xcdCompressionError r_error;
            VARIANT r_dataToCompress;
            VARIANT r_compressedData;
            VARIANT r_uncompressedData;
            SAFEARRAY *r_safeArray;
            char *r_safeArrayData;
            size_t r_length;

            r_length = strlen(loginRequestData);
            r_safeArray = SafeArrayCreateVector(VT_I1, 0, r_length);

            SafeArrayAccessData(r_safeArray, (void**)&r_safeArrayData);
            CopyMemory(r_safeArrayData, loginRequestData, r_length);
            SafeArrayUnaccessData(r_safeArray);

            VariantInit(&r_dataToCompress);
            VariantInit(&r_compressedData);
            VariantInit(&r_uncompressedData);

            r_dataToCompress.vt = VT_ARRAY | VT_I1;
            r_dataToCompress.parray = r_safeArray;

            //r_compressedData.vt = VT_ARRAY | VT_I1;
            //r_compressedData.parray = r_safeArray;

            IntPtr r_intPtrDataToCompress = (IntPtr)&r_dataToCompress;
            Object ^r_dataToCompressObject = Marshal::GetObjectForNativeVariant(r_intPtrDataToCompress);

            IntPtr r_intPtrCompressedData = (IntPtr)&r_compressedData;
            Object ^r_CompressedDataObject = Marshal::GetObjectForNativeVariant(r_intPtrCompressedData);

            r_error = compression->Compress(r_dataToCompressObject, r_CompressedDataObject, VARIANT_TRUE);
            //VariantClear(&r_dataToCompress);
            if (r_error != xcdCompressionError::xceSuccess)
                Console::WriteLine("Error Encountered!");

            if (r_CompressedDataObject != NULL) {
                PrintByteArrayVariant< unsigned char >(&r_compressedData);

            } else {
                Console::WriteLine("compressed Data Object NULL !");
            }}
    template< class DataType > static void PrintByteArrayVariant(VARIANT * variant) {
        DataType * data;
        SAFEARRAY * arrayDescriptor;
        int i, count;

        // Get the array descriptor from the variant
        arrayDescriptor = variant->parray;

        // Gain access to the array data
        SafeArrayAccessData(arrayDescriptor, (void **)&data);

        // Get the number of elements in the first dimension of the array
        count = arrayDescriptor->rgsabound[0].cElements / sizeof(DataType);

        int lineThreshold = 32 / sizeof(DataType);
        int groupThreshold = 4 / sizeof(DataType);
        char buffer[16];

        sprintf(buffer, "%%0%dX", sizeof(DataType) * 2);

        for (i = 0; i < count; i++)
        {
            // If we need to change line
            if ((i % lineThreshold) == 0 && i > 0)
                printf("\n");

            // If we need to seperate a group of data
            if ((i % groupThreshold) == 0)
                printf(" ");

            // Access the current index as we would a normal array
            printf(buffer, data[i]);
        }

        // Release access to the array data
        SafeArrayUnaccessData(arrayDescriptor);
    }

The return value of the compress method is xceSuccess , but r_compressedData is empty . Any idea about what might be wrong ? I had a hunch that the key for the library might have expired , but since I get xceSuccess as the return value I doubt that might be the case .

1 Answers1

0

To reassure you, the license key never expires, it will always be valid if it is used with the corresponding version of the component. If you use an old key with a newer version, then you will get a 'license key is too old' error message.

Version 4.2 is at least 15 years old, so my first suggestion would be to do some tests with the current version. Many issues and bugs have been fixed since v4.2, so perhaps one of those is responsible for the problems you are having.

You can find a link to download a trial of the latest version here:

https://xceed.com/xceed-zip-for-activex/

If you need further help, you can also contact us for email support at support@xceed.com

Diane-Xceed
  • 319
  • 1
  • 6
  • Version 4.2 does not has the 'license key is too old' error message in the xcdCompressionError enum. But , I agree this should not be the case . – Ravi Shukla May 23 '16 at 05:27