public byte[] ExtractToMemory(string fileToExtract)
        {
            UnzipUserFunctions unzipUserFunctions = PrepareCallBack();

            UnzipMemoryBuffer buf = new UnzipMemoryBuffer();

            // note: on successfull memory allocation and initialization,
            // Wiz_UnzipToMemory() returns a Longbool instead of a return code.
            // therefore the return value needs to be translated if < PK_BADERR.
            UnZipError res = NativeMethods.Wiz_UnzipToMemory(fileName, fileToExtract, ref unzipUserFunctions, ref buf);

            if (res == UnZipError.PK_WARN)
            {
                res = UnZipError.PK_OK;
            }
            else
            if (res == UnZipError.PK_OK)
            {
                res = UnZipError.PK_ERR;
            }

            if (res != UnZipError.PK_OK)
            {
                try
                {
                    NativeMethods.UzpFreeMemBuffer(ref buf);
                }
                catch
                {
                }
                return(null);
            }

            if (buf.TotalSize > 0)
            {
                try
                {
                    byte[] result = new byte[buf.TotalSize];
                    Marshal.Copy(buf.Buffer, result, 0, buf.TotalSize);
                    NativeMethods.UzpFreeMemBuffer(ref buf);
                    return(result);
                }
                catch
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 public static extern void UzpFreeMemBuffer(ref UnzipMemoryBuffer buf);
 public static extern UnZipError Wiz_UnzipToMemory(string zip, string file, ref UnzipUserFunctions zuf, ref UnzipMemoryBuffer retstr);