[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