IConverterSession in C#

S

Sonali Gupta

I am using IConverterSession interface in c #.
I declared the Interface is this way -

class NativeMethods
{
public enum CLSCTX
{
CLSCTX_INPROC_SERVER = 0x1,
CLSCTX_INPROC_HANDLER = 0x2,
CLSCTX_LOCAL_SERVER = 0x4,
CLSCTX_REMOTE_SERVER = 0x10,
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER
}


public static Guid CLSID_IConverterSession = new Guid("{4e3a7680-b77a-11d0-9da5-00c04fd65685}");

public static Guid IID_IConverterSession = new Guid("{4b401570-b77b-11d0-9da5-00c04fd65685}");

public enum ENCODINGTYPE
{
IET_BINARY = 0,
IET_BASE64 = 1,
IET_UUENCODE = 2,
IET_QP = 3,
IET_7BIT = 4,
IET_8BIT = 5,
IET_INETCSET = 6,
IET_UNICODE = 7,
IET_RFC1522 = 8,
IET_ENCODED = 9,
IET_CURRENT = 10,
IET_UNKNOWN = 11,
IET_BINHEX40 = 12,
IET_LAST = 13
}

public enum MIMESAVETYPE
{
SAVE_RFC822 = 0,
SAVE_RFC1521 = 1
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("4b401570-b77b-11d0-9da5-00c04fd65685")]
public interface IConverterSession
{
[PreserveSig]
int Placeholder0();

[PreserveSig]
int SetEncoding(
[In, MarshalAs(UnmanagedType.I4)] ENCODINGTYPE DispId
);

[PreserveSig]
int Placeholder1();

[PreserveSig]
int MIMEToMAPI(
[In, MarshalAs(UnmanagedType.Interface)]
Stream pstm,
[Out, MarshalAs(UnmanagedType.Interface)]
MailItem pmsg,
object pszSrcSrv,
uint ulFlags
);

[PreserveSig]
int MAPIToMIMEStm(
[In, MarshalAs(UnmanagedType.Interface)]
MailItem pmsg,
[Out, MarshalAs(UnmanagedType.Interface)]
Stream pstm,
uint ulFlags
);

[PreserveSig]
int Placeholder2();

[PreserveSig]
int Placeholder3();

[PreserveSig]
int Placeholder4();

[PreserveSig]
int SetTextWrapping(
bool fWrapText,
uint ulWrapWidth
);

[PreserveSig]
int SetSaveFormat(
[In, MarshalAs(UnmanagedType.I4)]
MIMESAVETYPE mstSaveFormat
);

[PreserveSig]
int Placeholder5();

[PreserveSig]
int Placeholder6();
}
}

I created an Instance of IConverterSession.I tried calling methods SetEncoding(), SetSaveFormat() on that instance, these methods are executed successfully. But when I call MIMEToMAPI() on the same instance it gives following exception - "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Here is the code I am using -

Type converter = Type.GetTypeFromCLSID(NativeMethods.CLSID_IConverterSession);
object obj = Activator.CreateInstance(converter);
NativeMethods.IConverterSession session = (NativeMethods.IConverterSession)obj;
int hr = session.SetEncoding(NativeMethods.ENCODINGTYPE.IET_QP);
hr = session.SetSaveFormat(NativeMethods.MIMESAVETYPE.SAVE_RFC822);

if (session != null)
{
Application olApp = new Application();
NameSpace nSpace = olApp.GetNamespace("MAPI");
MailItem msg = (MailItem)olApp.CreateItem(OlItemType.olMailItem);
FileStream stm = File.OpenRead("C:\\e.eml");
hr = session.MIMEToMAPI(stm, msg, null, 0);
msg.Save();
}

I also tried using CoCreateInstance() instead of Activator.CreateInstance() but that also doesn't helped.

Any input on this will be appreciated.

Thanks.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
F

fidq

Sonali Gupta wrote on 01/15/2009 07:39 ET
I am using IConverterSession interface in c #
I declared the Interface is this way

class NativeMethod

public enum CLSCT

CLSCTX_INPROC_SERVER = 0x1
CLSCTX_INPROC_HANDLER = 0x2
CLSCTX_LOCAL_SERVER = 0x4
CLSCTX_REMOTE_SERVER = 0x10
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER
CLSCTX_REMOTE_SERVER
CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLE



public static Guid CLSID_IConverterSession = ne
Guid("{4e3a7680-b77a-11d0-9da5-00c04fd65685}")

public static Guid IID_IConverterSession = ne
Guid("{4b401570-b77b-11d0-9da5-00c04fd65685}")

public enum ENCODINGTYP

IET_BINARY = 0
IET_BASE64 = 1
IET_UUENCODE = 2
IET_QP = 3
IET_7BIT = 4
IET_8BIT = 5
IET_INETCSET = 6
IET_UNICODE = 7
IET_RFC1522 = 8
IET_ENCODED = 9
IET_CURRENT = 10
IET_UNKNOWN = 11
IET_BINHEX40 = 12
IET_LAST = 1


public enum MIMESAVETYP

SAVE_RFC822 = 0
SAVE_RFC1521 =


[ComImport
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
[Guid("4b401570-b77b-11d0-9da5-00c04fd65685")
public interface IConverterSessio

[PreserveSig
int Placeholder0()

[PreserveSig
int SetEncoding
[In, MarshalAs(UnmanagedType.I4)] ENCODINGTYPE DispI
)

[PreserveSig
int Placeholder1()

[PreserveSig
int MIMEToMAPI
[In, MarshalAs(UnmanagedType.Interface)
Stream pstm
[Out, MarshalAs(UnmanagedType.Interface)
MailItem pmsg
object pszSrcSrv
uint ulFlag
)

[PreserveSig
int MAPIToMIMEStm
[In, MarshalAs(UnmanagedType.Interface)
MailItem pmsg
[Out, MarshalAs(UnmanagedType.Interface)
Stream pstm
uint ulFlag
)

[PreserveSig
int Placeholder2()

[PreserveSig
int Placeholder3()

[PreserveSig
int Placeholder4()

[PreserveSig
int SetTextWrapping
bool fWrapText
uint ulWrapWidt
)

[PreserveSig
int SetSaveFormat
[In, MarshalAs(UnmanagedType.I4)
MIMESAVETYPE mstSaveForma
)

[PreserveSig
int Placeholder5()

[PreserveSig
int Placeholder6()



I created an Instance of IConverterSession.I tried calling method
SetEncoding(), SetSaveFormat() on that instance, these methods are execute
successfully. But when I call MIMEToMAPI() on the same instance it give
following exception - "Attempted to read or write protected memory. Thi
is often an indication that other memory is corrupt.&quot

Here is the code I am using

Type converter Type.GetTypeFromCLSID(NativeMethods.CLSID_IConverterSession)
object obj = Activator.CreateInstance(converter)
NativeMethods.IConverterSession session (NativeMethods.IConverterSession)obj
int hr = session.SetEncoding(NativeMethods.ENCODINGTYPE.IET_QP)
hr = session.SetSaveFormat(NativeMethods.MIMESAVETYPE.SAVE_RFC822)

if (session != null

Application olApp = new Application()
NameSpace nSpace = olApp.GetNamespace("MAPI")
MailItem msg = (MailItem)olApp.CreateItem(OlItemType.olMailItem)
FileStream stm = File.OpenRead("C:e.eml")
hr = session.MIMEToMAPI(stm, msg, null, 0)
msg.Save()


I also tried using CoCreateInstance() instead of Activator.CreateInstance( bu
that also doesn't helped

Any input on this will be appreciated

Thanks

EggHeadCafe - .NET Developer Portal of Choic
http://www.eggheadcafe.com/default.aspx?ref=n
so what was the solution to fix your problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top