Get MailItem after Items.ItemAdd event

259 views Asked by At

I'm trying to get the size and the conversation index of an email after it's meved to the sent mail folder.

STDMETHODIMP CItemsEventListener::HandleItemAdd(DISPPARAMS* pDispParams, CString p_csDate, CString p_csTime)
{
    HRESULT l_hResult;
    CMailItem l_mailItem = NULL ;
    IDispatch * m_disp = pDispParams->rgvarg[1].pdispVal;
    l_hResult = m_disp->QueryInterface(IID_MailItemItems, (void**)&l_mailItem);
    //Do stuff
}

The QueryInterface method generates an exception. (access violation). Ps: Im using the very same CMailItem class with application events and it works well. What am I doing wrong?

Any help would be appreciated.

1

There are 1 answers

3
Dmitry Streblechenko On BEST ANSWER

Firstly, how is that method invoked?

Secondly, you are accessing the second parameter (rgvarg[1].pdispVal). You need to use the first parameter (rgvarg[0].pdispVal).