2013-05-21 1 views
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; 
    } 
} 

이것은 압축 해제를 수행하려는 제 클래스입니다.보호 된 메모리를 읽거나 쓰려고 시도했습니다. 이것은 종종 다른 메모리가 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를 할 수있는 기능입니다. 내가 항상 여기에서 찾을 수 있기를 바랍니다. 미리 감사드립니다.

+0

나는'ref'라고 선언 된 배열에 회의적입니다. – Medinoc

+1

예, 배열 문제입니다. 나는 네이티브 함수에 대한 문서를 이해할 수 없다. –

+0

하지만 그 해결책은 무엇입니까? 나는 이것을 어떻게 달성할까요? – Nikki

답변

1

Xceed의 CSharp Lib 또는 다른 Zip 라이브러리를 사용하지 않는 이유는 무엇입니까?
당신은 당신의 대리자를 정의해야

공공 대리인 INT DecompressMCX로 (INT의 hComp에서 IntPtr입니다, in_len이 uint, IntPtr입니다 밖으로, 심판 UINT 부울 EOD, out_len);

IntPrt에서 생성 할 때 압축을 실행하는 동안 가비지 수집기가 데이터를 이동하지 않도록 is를 수정하는 것이 중요합니다.

+0

왜냐하면 나는 증권 거래소 중 하나의 라이브 멀티 캐스트 데이터 바이트를 압축 해제한다고 가정하기 때문입니다. 그의 API는 압축을 위해 xceedzip을 사용한다고 말합니다. 그리고 작은 프로젝트로서 비싼 .net 구성 요소를 구입하는 것은 불가능합니다. – Nikki

+0

감사합니다. 위의 오류를 제거한 대리인을 변경 하겠지만 여전히 압축 풀기는 수행되지 않습니다. – Nikki

+0

xceedzip은 기본적으로 zlib입니다. 스트림 (IO.Streams)에 .NET Framework 클래스를 사용하려고 할 수도 있습니다. 어떤 외환이 그런 이상한 제안을하고 있는지. – weismat

관련 문제

 관련 문제