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