解压缩压缩富文本字段

问题描述:

我在包含压缩的RichText数据的数据表中有一个图像列。我想这是从Outlook(PR_RTF_COMPRESSED属性或其他)获得的。我需要解压缩它。使用C#,我正在尝试以下,但我得到一个System.Runtime.InteropServices.COMExceptions,无法弄清楚。解压缩压缩富文本字段

我发现了一些旧链接问这个问题,没有解决的答案。这里是我的代码使用C#的一个片段。

public Form1() 
    { 
     InitializeComponent(); 
     IStream streamOut; 

     string con = "connection string"; 
     SqlCommand command = new SqlCommand("select top 10 columnInCompressedRichTextFormat FROM tableWithCompressedRichTextData", new SqlConnection(dbConnectionString)); 
     DataTable x = new DataTable(); 
     SqlDataAdapter a = new SqlDataAdapter(command); 
     a.Fill(x); 
     a.Dispose(); 

     foreach (DataRow r in dtResults.Rows) 
     { 
      byte[] arrayOfBytes = (byte[]) r["columnInCompressedRichTextFormat"]; 
      IStream i = CreateIStreamFromBytes(arrayOfBytes); 
      WrapCompressedRTFStream(input, 0, out streamOut); 
     } 
    } 

    public IStream CreateIStreamFromBytes(byte[] bytes) 
    { 
     IntPtr hglobal = Marshal.AllocHGlobal(bytes.Length); 
     Marshal.Copy(bytes, 0, hglobal, bytes.Length); 

     IStream stream = null; 

     CreateStreamOnHGlobal(hglobal, true, out stream); 

     return stream; 
    } 

    [DllImport("Mapi32.dll", PreserveSig = false)] 
    private static extern void 
     WrapCompressedRTFStream(
     [MarshalAs(UnmanagedType.Interface)] IStream lpCompressedRTFStream, 
     uint ulflags, 
     [MarshalAs(UnmanagedType.Interface)] out IStream lpUncompressedRTFStream 
     ); 

    [DllImport("ole32.dll", PreserveSig = false)] 
    static extern int CreateStreamOnHGlobal(IntPtr hGlobal, 
     [MarshalAs(UnmanagedType.Bool)] bool fDeleteOnRelease, 
     [MarshalAs(UnmanagedType.Interface)] out IStream ppstm 
     ); 

    public const uint MAPI_MODIFY = 0x00000001; 
    public const uint STORE_UNCOMPRESSED_RTF = 0x00008000; 
} 

WrapCompressedRTFStream抛出错误。有任何想法吗?

很多谢谢。

+0

没有人可以帮你没有错误。请按照这里的指导http://idownvotedyoubecause.com/so/ImageOfAnException(扫描到有关获取异常详细信息的部分) – Will

+0

您还需要确保您正在加载msmapii32.dll的正确实例,而不是静态链接到mapi32。 DLL。查看MFCMAPI源代码以了解它是如何完成的。 –

+0

有谁知道差别下注WrapCompressedRTFStream和WrapCompressedRTFStreamEx? –