none
My application crashes while trying to send email using a distribution list using MAPI functions in Outlook 2013 SP1 in Windows 10 RRS feed

  • Question

  • Hi, 

    My application crashes while using MAPI functions. I have inserted the code block. It is crashing while calling  MAPIFreeBuffer(pspvADR); in SendNote. The same code block works fine with Office 365 and older versions of Outlook. Is there anything changed in Outlook 2013? 

    Any help would be greatly appreciated.

    Thanks

    hRes = m_pCSession->m_pFolders[INBOX]->CreateMessage(NULL, 0, &pNewMsg);		
    if ( S_OK == hRes )

    hRes = m_pCSession->SendNote(NULL, pNewMsg, pAlmEvt, fPaging);

    STDMETHODIMP CSession :: SendNote(HWND hDlg,LPMESSAGE pMsg) { LPSPropValue pspvEID = NULL, pspvOut = NULL, pspvADR = NULL; LPMESSAGE pSubmitMsg = NULL; ENTRYLIST eidMsg; HRESULT hRes; SizedADRLIST(1, adrList); LPADRLIST pADRList=NULL; CACString strTitle; CACString strBody; CACString strRecip; CString strError; pADRList = (LPADRLIST)&adrList; if (FAILED(hRes = MAPIAllocateBuffer(sizeof SPropValue * NUM_OUTBOUND_PROPS, (LPVOID *) &pspvOut))) { strError.Format( _T("Email, Failed to send email - MAPIAllocateBuffer1 failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); return hRes; } ZeroMemory(pspvOut, sizeof SPropValue * NUM_OUTBOUND_PROPS); if (FAILED(hRes = MAPIAllocateBuffer(sizeof SPropValue*2,(LPVOID *) &pspvADR))) { strError.Format( _T("Email, Failed to send email - MAPIAllocateBuffer2 failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); return hRes; } ZeroMemory(pspvADR, sizeof SPropValue*2); CTime tm = CTime::GetCurrentTime(); CString sTime = tm.Format("%H:%M:%S"); strTitle = "Test Email Received "; strTitle = strTitle + sTime; strBody = strTitle; strRecip = "ACC.EvtAlm"; pspvADR[0].ulPropTag = PR_DISPLAY_NAME; pspvADR[0].Value.lpszA = strRecip.GetBuffer(0); pspvADR[1].ulPropTag = PR_RECIPIENT_TYPE; pspvADR[1].Value.l = MAPI_TO; pADRList->cEntries = 1; pADRList->aEntries[0].rgPropVals = pspvADR; pADRList->aEntries[0].ulReserved1 = 0x0; pADRList->aEntries[0].cValues = 0x02; if (FAILED(hRes = m_pAddrBook->ResolveName(0,0,NULL,pADRList))) { strError.Format(_T("Email, Failed to send email - Failed for the recipient : %s Result: %0x \n"), strRecip, hRes); OutputDebugString(strError); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); goto Quit; } pspvOut[OBSUBJ].Value.LPSZ = strTitle.GetBuffer(0); pspvOut[OBBODY].Value.LPSZ = strBody.GetBuffer(0); pspvOut[OBFROM].Value.LPSZ = "Continuum"; pspvOut[OBFROM].ulPropTag = PR_SENDER_NAME; if (FAILED(hRes = SetOutgoingProps(pMsg,pspvOut))) { strError.Format( _T("Email, Failed to send email - SetOutgoingProps failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } if (FAILED(hRes = m_pFolders[OUTBOX] -> CreateMessage(NULL, 0, &pSubmitMsg))) { strError.Format( _T("Email, Failed to send email - CreateMessage failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } if (FAILED(hRes = pMsg -> CopyTo(0, NULL, NULL, (ULONG) hDlg, NULL, &IID_IMessage, pSubmitMsg, 0, NULL))) { strError.Format( _T("Email, Failed to send email - CopyTo failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } if (FAILED(hRes = pSubmitMsg -> ModifyRecipients(0, pADRList))) { strError.Format( _T("Email, Failed to send email - ModifyRecipients failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } if (FAILED(hRes = pSubmitMsg -> SubmitMessage(0))) { strError.Format( _T("Email, Failed to send email - SubmitMessage failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } if (FAILED(hRes = HrGetOneProp(pMsg,PR_ENTRYID, &pspvEID))) { strError.Format( _T("Email, Failed to send email - HrGetOneProp failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } eidMsg.cValues = 1; eidMsg.lpbin = &pspvEID[0].Value.bin; pMsg -> Release(); // can't delete an open message if (FAILED(hRes = m_pFolders[INBOX] -> DeleteMessages(&eidMsg, (ULONG)hDlg, NULL, MESSAGE_DIALOG))) { strError.Format( _T("Email, Failed to send email - DeleteMessages failed in CSession::SendNote, Result is %0x \n"),hRes); CACEmail::SendLogMessage ( strError.GetBuffer( 0 ) ); OutputDebugString(strError); goto Quit; } Quit: MAPIFreeBuffer(pspvADR); if (pADRList) FreePadrlist(pADRList); if (pSubmitMsg) pSubmitMsg -> Release(); MAPIFreeBuffer(pspvEID); MAPIFreeBuffer(pspvOut); strTitle.ReleaseBuffer(); strBody.ReleaseBuffer(); return hRes; }


    • Edited by USM83 Thursday, August 13, 2020 4:16 PM
    Thursday, August 13, 2020 4:12 PM

All replies

  • You do not need to free pspvADR - FreePAdrList does that.

    To be more specific, it gets freed and replaced by ResolveName, and then (possibly) by ModifyRecipients. FreePAdrList frees each row separately, and then the parent AdrList structure.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, August 13, 2020 4:28 PM
  • Thank You for your reply. 

    The same code is working fine with Office 365 and older versions of Outlook. Is there anything changed in Outlook 2013 SP1 which could be causing the crash.

    Monday, August 17, 2020 3:30 PM
  • Nothing has changed - that requirement's been in place ever since MS Mail back in the early  1990s.

    Some versions of Outlook (if you are lucky) can detect that the memory has already been freed if it has not been reused. But the problem is in your code - the memory is double freed.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, August 17, 2020 3:38 PM