xceedCompressionClass compress返回xceSuccess但不压缩

时间:2016-05-18 05:06:28

标签: compression xceed

我正在使用Xceedzip.dll COM Component 4.2进行内存压缩(我指的是this文档)。

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);
    }

compress方法的返回值是xceSuccess,但r_compressedData为空。 什么可能是错的?我预感到库的密钥可能已过期,但由于我将xceSuccess作为返回值,我怀疑可能是这种情况。

1 个答案:

答案 0 :(得分:0)

为了让您放心,许可证密钥永不过期,如果它与相应版本的组件一起使用,它将始终有效。如果您使用较旧版本的旧密钥,那么您将获得一个太旧的许可证密钥&#39;错误信息。

版本4.2至少有15年的历史,所以我的第一个建议是使用当前版本进行一些测试。自v4.2以来,许多问题和错误已得到修复,因此可能其中一个问题对您遇到的问题负责。

您可以在此处找到下载最新版试用版的链接:

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

如果您需要进一步的帮助,也可以通过support@xceed.com

与我们联系以获取电子邮件支持