Problem Opening Email when using InvokeHelper in C++
-
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
-
what object is
m_outlook
and what method is0x10a
? I don't think your problem is with invokeHelper, I think it's with the underlying method in the m_outlook objectHi 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?
-
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?
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?
-
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?
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.
-
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.
-
in your original code snippet, you're using a
CString
, you need to use aBSTR
use theAllocSysString()
method inCString
that may helpOk, so are you saying I need to convert CString to BSTR and AllocSysString() to do this?
-
in your original code snippet, you're using a
CString
, you need to use aBSTR
use theAllocSysString()
method inCString
that may helpJust 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?
-
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?
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);
-
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);
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?
-
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);
Ignore my last message - I tried your solution and it worked! Thanks for your help!