J
jessi
I'm QI ing the IDisptach for Outlook Mailitem but it says Interface not
suported, Im pasting the code below.
In the below code
hRes=pMailItem->QueryInterface((__uuidof(OL::_MailItem),(void**)&pMail); is
returning the error, -2147467262, is some thing like Interface Not
supported.
Tell me where Im doing wrong. Just I want to cast the IDispatch to Outlook
Mailitem. (just for precautionary measures im QI ing it, even im unable to
type cast it, help me in doing so.
Here Im sending the outlook item as an attachment which i have assigned to
m_AttchObject.
STDMETHODIMP Cmessage:ut_attachobject(LPDISPATCH newVal)
{
m_AttchObject = newVal;
}
Later in somementhod im calling HrOLELink(m_AttchObject ,&lpMessage);
Here lpMessage is the message object for which I want to add the
item(m_AttachObject) as an attachment.
STDMETHODIMP HrOLELink(IDispatch *pMailItem,LPMESSAGE *lpMessage)
{
OL::_MailItem *pMail;
HRESULT hRes=NULL;
IUnknown* PI=NULL;
LPMESSAGE NewMessage;
LPATTACH pAtt=NULL;
LPSPropProblemArray pProblems= NULL;
ULONG ulAttNum;
enum {METHOD,RENDERING,NUM_ATT_PROPS};
SPropValue spvAttach[NUM_ATT_PROPS];
hRes= pMailItem->QueryInterface((__uuidof(OL::_MailItem),(void**)&pMail);
if(SUCCEEDED(hRes))
{
LPUNKNOWN lpUnk = pMail->MAPIOBJECT;
LPMESSAGE *lpMsgToAdd ;
hRes=lpUnk->QueryInterface(IID_IMessage,(void**)&lpMsgToAdd);
hRes= (*lpMessage)->CreateAttach(NULL,0,&ulAttNum, &pAtt);
if (FAILED(hRes)) goto quit;
spvAttach[METHOD].ulPropTag = PR_ATTACH_METHOD;
spvAttach[METHOD].Value.l = ATTACH_EMBEDDED_MSG;
// Don't render it as anything, just attach it.
spvAttach[RENDERING].ulPropTag = PR_RENDERING_POSITION;
spvAttach[RENDERING].Value.l = -1;
hRes= pAtt->SetProps(NUM_ATT_PROPS, (LPSPropValue)&spvAttach,NULL);
if (FAILED(hRes)) goto quit;
hRes= pAtt->OpenProperty( PR_ATTACH_DATA_OBJ, (LPIID) &IID_IMessage,0,
MAPI_MODIFY| MAPI_CREATE,
(LPUNKNOWN *) &NewMessage);
if (FAILED(hRes)) goto quit;
hRes=(*lpMsgToAdd)->CopyTo(0,NULL,NULL,0,NULL,&IID_IMessage,(LPVOID)NewMess
age,0,&pProblems );
if (FAILED(hRes)) goto quit;
hRes = pAtt->SaveChanges(0);
if (FAILED(hRes)) goto quit;
}
quit:
if (pAtt)
pAtt->Release();
return hRes;
}
suported, Im pasting the code below.
In the below code
hRes=pMailItem->QueryInterface((__uuidof(OL::_MailItem),(void**)&pMail); is
returning the error, -2147467262, is some thing like Interface Not
supported.
Tell me where Im doing wrong. Just I want to cast the IDispatch to Outlook
Mailitem. (just for precautionary measures im QI ing it, even im unable to
type cast it, help me in doing so.
Here Im sending the outlook item as an attachment which i have assigned to
m_AttchObject.
STDMETHODIMP Cmessage:ut_attachobject(LPDISPATCH newVal)
{
m_AttchObject = newVal;
}
Later in somementhod im calling HrOLELink(m_AttchObject ,&lpMessage);
Here lpMessage is the message object for which I want to add the
item(m_AttachObject) as an attachment.
STDMETHODIMP HrOLELink(IDispatch *pMailItem,LPMESSAGE *lpMessage)
{
OL::_MailItem *pMail;
HRESULT hRes=NULL;
IUnknown* PI=NULL;
LPMESSAGE NewMessage;
LPATTACH pAtt=NULL;
LPSPropProblemArray pProblems= NULL;
ULONG ulAttNum;
enum {METHOD,RENDERING,NUM_ATT_PROPS};
SPropValue spvAttach[NUM_ATT_PROPS];
hRes= pMailItem->QueryInterface((__uuidof(OL::_MailItem),(void**)&pMail);
if(SUCCEEDED(hRes))
{
LPUNKNOWN lpUnk = pMail->MAPIOBJECT;
LPMESSAGE *lpMsgToAdd ;
hRes=lpUnk->QueryInterface(IID_IMessage,(void**)&lpMsgToAdd);
hRes= (*lpMessage)->CreateAttach(NULL,0,&ulAttNum, &pAtt);
if (FAILED(hRes)) goto quit;
spvAttach[METHOD].ulPropTag = PR_ATTACH_METHOD;
spvAttach[METHOD].Value.l = ATTACH_EMBEDDED_MSG;
// Don't render it as anything, just attach it.
spvAttach[RENDERING].ulPropTag = PR_RENDERING_POSITION;
spvAttach[RENDERING].Value.l = -1;
hRes= pAtt->SetProps(NUM_ATT_PROPS, (LPSPropValue)&spvAttach,NULL);
if (FAILED(hRes)) goto quit;
hRes= pAtt->OpenProperty( PR_ATTACH_DATA_OBJ, (LPIID) &IID_IMessage,0,
MAPI_MODIFY| MAPI_CREATE,
(LPUNKNOWN *) &NewMessage);
if (FAILED(hRes)) goto quit;
hRes=(*lpMsgToAdd)->CopyTo(0,NULL,NULL,0,NULL,&IID_IMessage,(LPVOID)NewMess
age,0,&pProblems );
if (FAILED(hRes)) goto quit;
hRes = pAtt->SaveChanges(0);
if (FAILED(hRes)) goto quit;
}
quit:
if (pAtt)
pAtt->Release();
return hRes;
}