[英]DLLImport(C code) C# Attempted to read or write protected memory. This is often an indication that other memory is corrupt”
[英]Attempted to read or write protected memory. This is often an indication that other memory is corrupt in c# (Access violation)
[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
是我想要調用的函數。 希望最好的解決方案,因為我總是在這里找到。 提前致謝。
您不使用 Xceed 的 CSharp Lib 或替代 Zip 庫的任何原因?
您應該將您的委托定義為
公共委托 int DecompressMCX(int hComp,IntPtr in, uint in_len, IntPtr out, ref uint out_len, bool eod);
在生成in
IntPtr 時,修復它很重要,以便垃圾收集器在壓縮運行時不會移動 in 數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.