【发布时间】:2023-03-26 13:00:01
【问题描述】:
[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
是我想要调用的函数。 希望得到最好的解决方案,就像我在这里总能找到的那样。提前致谢。
【问题讨论】:
-
我对声明为
ref的这些数组持怀疑态度。 -
是的,数组是问题所在。请注意,我无法理解本机函数的文档。
-
但是解决方案是什么,因为我应该怎么做到这一点????
-
使用 Xceed ZIP 库最简单的方法是使用他们的 .net 组件。试图 p/invoke 本机版本只是受虐狂。更重要的是,你为什么要使用这个库而不是原生的 .net 库?例如,
System.IO.Compression.ZipArchive。 -
因为我想解压缩证券交易所之一的实时多播数据字节,其 API 说使用 xceedzip 解压缩。而且作为一个小项目,购买这么昂贵的.net组件对我来说是不可能的。
标签: c# dll pinvoke access-violation