views:

312

answers:

3

Hello,

I am using VS 2008 C# Windows Application.

I have this DLL Import I am trying to use.

[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.

How do I pass the string into the 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);

The first error I get is "cannot convert from 'string' to '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.

[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.

A: 

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

Try out com interop or p-invoke .net technologies to use legacy code.

Andrew Florko
I tried to use it with the com interop, but I failed to get it working. Looking at the code on the link can you help me use it with interop? (I do not want to learn C++ at this point.) As for Analogous code in .net. I have not found any as of yet.
Code Smack
May be this article will help:http://www.c-sharpcorner.com/uploadfile/rambab/outlookintegration10282006032802am/outlookintegration.aspx
Andrew Florko
A: 

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.

What this will let you do is create C++ code to perform your work, while exposing a managed class to call the method. 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".

Will Eddins
well, that would be great, but like you said I would have to learn C++ (I am not ready to spend the time on that just yet) I just need to figure out how to use the code on the link in my post within a C# windows form.
Code Smack
A: 

UCOMIStream is deprecated, use ComTypes.Istream instead. Then look at http://stackoverflow.com/questions/385684/system-runtime-interopservices-comtypes-istream-to-system-io-stream

MSalters
Any guidance on how to move strings in and out of the ISTREAM object?
Code Smack
IStream is not an (existing) object; it's an interface. You'll have to implement it in your own class.
MSalters