QI MailItem from IDispatch

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::put_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;

}
 
K

Kim Gräsman

Hi Jessi,
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.

QI is not a precaution, it is necessary, so it's a good thing you're using
it.
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)
{

There may be some given context I am missing here, but what type is
m_AttachObject? Who calls
Cmessage::put_attachobject, and what is passed as the newVal parameter?
 
S

satish

Thx Kim,
Im able to resolve it.However m_AttachObject is LPDISPATCH and the
client im calling it from Outlook designer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top