0
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int DecompressMCX(object hComp,ref byte[] @in, uint @in_len, ref byte[] @out, ref uint out_len, bool eod);

public class XceedCompressor
{

    [DllImport("kernel32.dll")]
    public static extern IntPtr LoadLibrary(string dllToLoad);

    [DllImport("kernel32.dll")]
    public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);       

    byte[] OutRec = new byte[1024 * 100];
    uint outlen;
    DecompressMCX DecompressDelegate;
    int b ;
    unsafe int l;

    public XceedCompressor()
    {
        IntPtr pDll = LoadLibrary(@"xceedzip.dll");
        IntPtr pAddressOfFunctionToCall = GetProcAddress(pDll, "XcUncompress");
        DecompressDelegate = (DecompressMCX)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(DecompressMCX));
    }

    public byte[] Decompress(byte[] InRecArr)
    {
        outlen = 0;
        l = DecompressDelegate(b, ref InRecArr, (uint)InRecArr.Length, ref OutRec, ref outlen, true);
        return OutRec;
    }
}

这是我要进行减压的课程。

XceedCompressor xcd = new XceedCompressor ();
xcd.Decompress(some data already compressed with the same library);

但它给出的错误是“尝试读取或写入受保护的内存。这通常表明其他内存已损坏。”

http://doc.xceedsoft.com/products/Xceedzip/Uncompress_method.html

是我要调用的功能。希望有最好的解决方案,就像我在这里总能找到的那样。提前致谢。

4

1 回答 1

1

有什么理由不使用 Xceed 的 CSharp Lib 或替代 Zip 库?
您应该将您的委托定义为

公共委托 int DecompressMCX(int hComp,IntPtr in, uint in_len, IntPtr out, ref uint out_len, bool eod);

生成inIntPtr 时,修复它很重要,这样垃圾收集器就不会在压缩运行时移动输入数据。

于 2013-05-21T10:36:41.847 回答