简体   繁体   English

使用C#访问“ Mapi32.dll”

[英]Accessing “Mapi32.dll” with C#

I am using VS 2008 C# Windows Application. 我正在使用VS 2008 C#Windows应用程序。

I have this DLL Import I am trying to use. 我正在尝试使用此DLL导入。

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

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

I have a compressed string that is in CompressedRFTFormat. 我有一个CompressedRFTFormat中的压缩字符串。

How do I pass the string into the WrapCompressedRTFStream? 如何将字符串传递给WrapCompressedRTFStream? I do not understand what the method is expecting. 我不明白该方法的期望。

I am trying to use it on a button. 我正在尝试在按钮上使用它。

RichText1.text = WrapCompressedRTFStream(_CompressedRichText.ToString(),something,somethingelse); RichText1.text = WrapCompressedRTFStream(_CompressedRichText.ToString(),某物,某物);

The first error I get is "cannot convert from 'string' to 'System.Runtime.InteropServices.UCOMIStream" 我得到的第一个错误是“无法从'string'转换为'System.Runtime.InteropServices.UCOMIStream”

I hope someone who understands this posts an answer that helps! 希望了解此内容的人发布有助于您解决问题的答案!

ok, so I end up in the same situation when I use the IStream. 好的,所以当我使用IStream时会遇到相同的情况。

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

The real issue here is I do not understand what / how to deal with the input and output of this method. 真正的问题是我不了解该方法的输入和输出如何/如何处理。

I suppose it's not a good idea to use legacy native-code libraries & I would investigate some more time to find analogous code in .net 我想使用遗留的本机代码库不是一个好主意,我将花费更多的时间在.net中查找类似的代码

Try out com interop or p-invoke .net technologies to use legacy code. 尝试使用com interopp调用.net技术来使用旧版代码。

If you can't find a native .NET method for doing this, a good approach would be to contain your approach in a Managed C++ wrapper. 如果找不到用于执行此操作的本机.NET方法,则好的方法是将您的方法包含在托管C ++包装器中。

What this will let you do is create C++ code to perform your work, while exposing a managed class to call the method. 这将使您做的是创建C ++代码来执行您的工作,同时公开托管类以调用该方法。 This may be more complicated since it will require you to learn Managed C++, but allows you to do any C++ work necessary, returning a .NET string containing your "answer". 这可能会更复杂,因为它将要求您学习托管C ++,但允许您执行任何必要的C ++工作,并返回包含“答案”的.NET字符串。

UCOMIStream is deprecated, use ComTypes.Istream instead. 不建议使用UCOMIStream,请改用ComTypes.Istream。 Then look at System.Runtime.InteropServices.ComTypes.IStream to System.IO.Stream 然后查看System.Runtime.InteropServices.ComTypes.IStream到System.IO.Stream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM