Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem Opening Email when using InvokeHelper in C++

Problem Opening Email when using InvokeHelper in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpfhelpquestion
18 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Just go to MSDN and use the search box for the function that you are trying to use.

    The best things in life are not things.

    U Offline
    U Offline
    User 2970611
    wrote on last edited by
    #7

    Thanks I will have ago to see if I can find what I need, but do you mind if I can call on your help if I get stuck?

    L 1 Reply Last reply
    0
    • U User 2970611

      Thanks I will have ago to see if I can find what I need, but do you mind if I can call on your help if I get stuck?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #8

      I am afraid I have not used this function myself, but here[^] is a link that may be of use.

      The best things in life are not things.

      1 Reply Last reply
      0
      • U User 2970611

        Hi I have an MFC Project, and what this project does is to allow a user to Open an in a number of different way, either a new email message, a new email message using a template or open an existing email message. The MFC is part of a much larger application and some of the data for selecting the correct email templates and opening an existing email comes from a web service. My MFC Project works to a certain, I can get Outlook, I can get my Web Service with my email template, but when I reach the point of Open the Email either a new one, open or otherwise it fails. Here is my code snippet: CString emailPath; LPDISPATCH mailItem; static BYTE params [] = VIS_BSTR VTS_VARIANT ; m_outlook->(0x10a, DISPATCH_METHOD, VT_DISPATCH, (void*)&mailItem, params, emailPath, NULL) //falls over here! outlookMailItem = new COleDispatchDriver(mailItem); What I have done wrong? Thanks

        B Offline
        B Offline
        barneyman
        wrote on last edited by
        #9

        what object is m_outlook and what method is 0x10a? I don't think your problem is with invokeHelper, I think it's with the underlying method in the m_outlook object

        U 1 Reply Last reply
        0
        • B barneyman

          what object is m_outlook and what method is 0x10a? I don't think your problem is with invokeHelper, I think it's with the underlying method in the m_outlook object

          U Offline
          U Offline
          User 2970611
          wrote on last edited by
          #10

          Hi The code is based upon this website: http://repositorium.googlecode.com/svn/trunk/AbstractSpoon/OutlookImpExp/Source/msoutl.cpp Yes, there is a mistake it should say m_outlook->invokehelper and m_outlook is the name for outlook object which I have called before to start MS Outlook. The next step is to open an email template that is given a template file path and to display this to the user. I have tried searching MSDN for help, but I can't find any help. The code I have used is based upon this from the website above: LPDISPATCH _Application::CreateItemFromTemplate(LPCTSTR TemplatePath, const VARIANT& InFolder) { LPDISPATCH result; static BYTE parms[] = VTS_BSTR VTS_VARIANT; InvokeHelper(0x10b, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, TemplatePath, &InFolder); return result; } I have tried passing in NULL for the last parameter as there is no folder involved, but I am guessing on a lot of this because I have no idea what the exact definition of the method in MS Outlook for 0x10a or 0x10b. As I have said I can't find in MSDN any definition for this. Can you help?

          B 1 Reply Last reply
          0
          • U User 2970611

            Hi The code is based upon this website: http://repositorium.googlecode.com/svn/trunk/AbstractSpoon/OutlookImpExp/Source/msoutl.cpp Yes, there is a mistake it should say m_outlook->invokehelper and m_outlook is the name for outlook object which I have called before to start MS Outlook. The next step is to open an email template that is given a template file path and to display this to the user. I have tried searching MSDN for help, but I can't find any help. The code I have used is based upon this from the website above: LPDISPATCH _Application::CreateItemFromTemplate(LPCTSTR TemplatePath, const VARIANT& InFolder) { LPDISPATCH result; static BYTE parms[] = VTS_BSTR VTS_VARIANT; InvokeHelper(0x10b, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, TemplatePath, &InFolder); return result; } I have tried passing in NULL for the last parameter as there is no folder involved, but I am guessing on a lot of this because I have no idea what the exact definition of the method in MS Outlook for 0x10a or 0x10b. As I have said I can't find in MSDN any definition for this. Can you help?

            B Offline
            B Offline
            barneyman
            wrote on last edited by
            #11

            Looking at the type Library for Microsoft Outlook ...

            [id(0x0000010a), helpcontext(0x000002ca)]
            IDispatch* CreateItem([in] OlItemType ItemType);

            [id(0x0000010b), helpcontext(0x000002cb)]
            IDispatch* CreateItemFromTemplate(
            [in] BSTR TemplatePath,
            [in, optional] VARIANT InFolder);

            which gets me to ... http://msdn.microsoft.com/en-us/library/aa220081(v=office.11).aspx[^] Does that help any?

            U 1 Reply Last reply
            0
            • B barneyman

              Looking at the type Library for Microsoft Outlook ...

              [id(0x0000010a), helpcontext(0x000002ca)]
              IDispatch* CreateItem([in] OlItemType ItemType);

              [id(0x0000010b), helpcontext(0x000002cb)]
              IDispatch* CreateItemFromTemplate(
              [in] BSTR TemplatePath,
              [in, optional] VARIANT InFolder);

              which gets me to ... http://msdn.microsoft.com/en-us/library/aa220081(v=office.11).aspx[^] Does that help any?

              U Offline
              U Offline
              User 2970611
              wrote on last edited by
              #12

              Thanks for your email. I had a look at the link you gave me from MSDN. However, I am still just as confused and still stuck. The code I have been given is that in my original posting. I have an Outlook object, because this code is not falling over, but I can create a mail item for a template.

              B 1 Reply Last reply
              0
              • U User 2970611

                Thanks for your email. I had a look at the link you gave me from MSDN. However, I am still just as confused and still stuck. The code I have been given is that in my original posting. I have an Outlook object, because this code is not falling over, but I can create a mail item for a template.

                B Offline
                B Offline
                barneyman
                wrote on last edited by
                #13

                in your original code snippet, you're using a CString, you need to use a BSTR use the AllocSysString() method in CString that may help

                U 2 Replies Last reply
                0
                • B barneyman

                  in your original code snippet, you're using a CString, you need to use a BSTR use the AllocSysString() method in CString that may help

                  U Offline
                  U Offline
                  User 2970611
                  wrote on last edited by
                  #14

                  Ok, so are you saying I need to convert CString to BSTR and AllocSysString() to do this?

                  1 Reply Last reply
                  0
                  • B barneyman

                    in your original code snippet, you're using a CString, you need to use a BSTR use the AllocSysString() method in CString that may help

                    U Offline
                    U Offline
                    User 2970611
                    wrote on last edited by
                    #15

                    Just to let you know that I followed what you said, but it threw an unhandled exception. Here is the code as it on screen OpenOutlookNewMessageWithMsgFile(CString filePath) //Call CreateItemFromTemplate to create new mailitem using late binding LPDISPATH mailItem static BYTE params[] = VTS_BSTR VTS_VARIANT ; BSTR bFilePath = filePath.AllocSysString(); outlookApp->InvokeHelper(0x10b, DISPATCH_METHOD, VT_DISPATCH, (void*)&mailItem, params, bFilePath, NULL); outlookMailItem = new COleDispatchDriver(mailItem); //Set User Properties SetProperties(); //Set Display of Mail Item VARIANT_BOOL modal = VARIANT_FALSE; static BYTE params2[] = VTS_I4; outlookMailItem->InvokeHelper(oxf0a6,DISPATCH_METHOD,VT_EMPTY, NULL, params2, &modal); So, this is the whole for creating an email from template, but it is on outlookApp->InvokeHelper that I am having a problem. What am I doing wrong?

                    R 1 Reply Last reply
                    0
                    • U User 2970611

                      Just to let you know that I followed what you said, but it threw an unhandled exception. Here is the code as it on screen OpenOutlookNewMessageWithMsgFile(CString filePath) //Call CreateItemFromTemplate to create new mailitem using late binding LPDISPATH mailItem static BYTE params[] = VTS_BSTR VTS_VARIANT ; BSTR bFilePath = filePath.AllocSysString(); outlookApp->InvokeHelper(0x10b, DISPATCH_METHOD, VT_DISPATCH, (void*)&mailItem, params, bFilePath, NULL); outlookMailItem = new COleDispatchDriver(mailItem); //Set User Properties SetProperties(); //Set Display of Mail Item VARIANT_BOOL modal = VARIANT_FALSE; static BYTE params2[] = VTS_I4; outlookMailItem->InvokeHelper(oxf0a6,DISPATCH_METHOD,VT_EMPTY, NULL, params2, &modal); So, this is the whole for creating an email from template, but it is on outlookApp->InvokeHelper that I am having a problem. What am I doing wrong?

                      R Offline
                      R Offline
                      Roger Broomfield
                      wrote on last edited by
                      #16

                      I believe your problem is with the last parameter to "CreateItemFromTemplate". NULL is not the correct way to pass an [in, optional] VARIANT. There is no need to convert filePath to a BSTR, presuming that "outlookApp" is indeed an COleDispatchDriver. Do cast it to an LPCTSTR, InvokeHelper expects an in param defined as a VTS_BSTR to be an LPCTSTR, MFC's implementation of COleDispathDrvier will do the BSTR conversion for you inside the InvokeHelper call.

                      OpenOutlookNewMessageWithMsgFile(CString filePath)
                      {
                      COleVariant varOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                      LPDISPATCH mailItem;
                      static BYTE params [] = VTS_BSTR VTS_VARIANT ;

                      outlookApp->InvokeHelper(0x10b, DISPATCH\_METHOD, VT\_DISPATCH, (void\*)&mailItem, params, (LPCTSTR)filePath, &varOptional);
                      
                      U 2 Replies Last reply
                      0
                      • R Roger Broomfield

                        I believe your problem is with the last parameter to "CreateItemFromTemplate". NULL is not the correct way to pass an [in, optional] VARIANT. There is no need to convert filePath to a BSTR, presuming that "outlookApp" is indeed an COleDispatchDriver. Do cast it to an LPCTSTR, InvokeHelper expects an in param defined as a VTS_BSTR to be an LPCTSTR, MFC's implementation of COleDispathDrvier will do the BSTR conversion for you inside the InvokeHelper call.

                        OpenOutlookNewMessageWithMsgFile(CString filePath)
                        {
                        COleVariant varOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                        LPDISPATCH mailItem;
                        static BYTE params [] = VTS_BSTR VTS_VARIANT ;

                        outlookApp->InvokeHelper(0x10b, DISPATCH\_METHOD, VT\_DISPATCH, (void\*)&mailItem, params, (LPCTSTR)filePath, &varOptional);
                        
                        U Offline
                        U Offline
                        User 2970611
                        wrote on last edited by
                        #17

                        Thank you for your reply. Because I do not have a folder for the email to be created in and wish to use the default folder inside Outlook, what parameter should I use, or should I only pass in the parameters I am using and Outlook can then interpret this?

                        1 Reply Last reply
                        0
                        • R Roger Broomfield

                          I believe your problem is with the last parameter to "CreateItemFromTemplate". NULL is not the correct way to pass an [in, optional] VARIANT. There is no need to convert filePath to a BSTR, presuming that "outlookApp" is indeed an COleDispatchDriver. Do cast it to an LPCTSTR, InvokeHelper expects an in param defined as a VTS_BSTR to be an LPCTSTR, MFC's implementation of COleDispathDrvier will do the BSTR conversion for you inside the InvokeHelper call.

                          OpenOutlookNewMessageWithMsgFile(CString filePath)
                          {
                          COleVariant varOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                          LPDISPATCH mailItem;
                          static BYTE params [] = VTS_BSTR VTS_VARIANT ;

                          outlookApp->InvokeHelper(0x10b, DISPATCH\_METHOD, VT\_DISPATCH, (void\*)&mailItem, params, (LPCTSTR)filePath, &varOptional);
                          
                          U Offline
                          U Offline
                          User 2970611
                          wrote on last edited by
                          #18

                          Ignore my last message - I tried your solution and it worked! Thanks for your help!

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups