[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;
}
}
這是我想要執行解壓縮的類。試圖讀取或寫入受保護的內存。這通常表明其他內存在c#中已損壞(訪問衝突)
XceedCompressor xcd = new XceedCompressor();
xcd.Decompress(some data already compressed with the same library);
但它給錯誤的「嘗試讀取或寫入受保護的內存。這通常是指示其他內存已損壞。」
http://doc.xceedsoft.com/products/Xceedzip/Uncompress_method.html
是我想要的PInvoke功能。 希望能找到最好的解決方案,正如我總是在這裏找到的。提前致謝。
我對這些聲明爲'ref'的數組持懷疑態度。 – Medinoc
是的,陣列是問題。我無法理解本地函數的文檔。 –
但那麼什麼是解決方案,因爲我應該實現這個任何如何? – Nikki