none
MFC put_RTFBody Error RRS feed

  • Question

  • Hi All,

    I face a problem: See mtI is an CAppointmentItem and ml is an CMailItem. HtmlBody is a CString.

    Here is the problem: As CAppointmentItem can't set HTMLBody and I don't know how to create rtfbody, I want to set ml's htmlbody so that I can get rtfbody from it.

    And code below:

    mtI = app.CreateItem(1);
    ml = app.CreateItem(0);
    ml.put_HTMLBody(HtmlBody);
    VARIANT RtfBody=ml.get_RTFBody();
    mtI.put_RTFBody(RtfBody);
    ml=NULL;

    But it tells me that param error!?

    I know that ml.get_RTFBody(); returns VARIANT, and mtI.put_RTFBody(RtfBody); need a VARIANT. Why it is error? And what should I do to solve the problem?

    Looking forward to hearing from you~~

    Thanks very much.

    Thursday, December 10, 2015 9:36 AM

All replies

  • Hi All,

    I face a problem: See mtI is an CAppointmentItem and ml is an CMailItem. HtmlBody is a CString.

    Here is the problem: As CAppointmentItem can't set HTMLBody and I don't know how to create rtfbody, I want to set ml's htmlbody so that I can get rtfbody from it.

    And code below:

    mtI = app.CreateItem(1);
    ml = app.CreateItem(0);
    ml.put_HTMLBody(HtmlBody);
    VARIANT RtfBody=ml.get_RTFBody();
    mtI.put_RTFBody(RtfBody);
    ml=NULL;

    But it tells me that param error!?

    I know that ml.get_RTFBody(); returns VARIANT, and mtI.put_RTFBody(RtfBody); need a VARIANT. Why it is error? And what should I do to solve the problem?

    Looking forward to hearing from you~~

    Thanks very much.

    I didn't see the reference for CAppointmentItem to verify the parameters being passed to it are valid. Do you have a link for it?

    separately, I think you may need to call save on mtI before trying to get the RTF format, but that is a guess.

    • Edited by Joel_Z Thursday, December 10, 2015 2:10 PM
    Thursday, December 10, 2015 2:09 PM
  • Try to save the message before reading RTF (ml.Save) - that is when the store provider synchronizes the 3 flavors of the message body.

    Keep in mind that most likely you will end up with RTF encoded HTML, which the appointment item (or any RTF editor) will not be able to render correctly.

    You will have better luck using the Word Object Model to convert HTLl to RTF.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, December 10, 2015 5:21 PM