none
How to get contact picture data using mapi api in MFC? RRS feed

All replies

  • Hello Vijay,

    Images are stored as attachments. Did you have a chance to look at the Attachments property of the ContactItem class from the Outlook object model?

    You can find a sample code using MFC here. Why do you need to use Extended MAPI if all properties are available through the OOM?

    Tuesday, April 22, 2014 6:52 AM
  • Thanks for reply 

    I don't use extended MAPI. i used core MAPI API.

    http://msdn.microsoft.com/en-us/library/office/cc815463(v=office.15).aspx

    i put my code in below 

    m_contact_prop is IMAPIPROP object

    **********************************************************

    LPMAPITABLE pTable = NULL;
    result = ((IMessage *)m_contact_prop)->GetAttachmentTable(0, &pTable);
    if(SUCCEEDED(result))
    {
    ULONG rowCount;
    if(!FAILED(pTable->GetRowCount(0, &rowCount)))
    {
    SRowSet *rows;
    SPropTagArray *columns;
    pTable->QueryColumns(0, &columns);
    ULONG nColumns = columns->cValues;
    bool isOver = false;
    if(!FAILED(pTable->QueryRows(rowCount, TBL_NOADVANCE, &rows)))
    {
    SPropValue value;
    int attachmentNum;
    for(int i = 0; i < (int)rowCount; i++)
    {
    for(int j = 0; j < (int)nColumns && !isOver; j++)
    {
    value = rows->aRow[i].lpProps[j];
    switch(value.ulPropTag)
    {
    case PR_ATTACH_NUM:
    {
    attachmentNum = value.Value.l;
    LPATTACH at;
    HRESULT hr = ((IMessage *)m_contact_prop)->OpenAttach(attachmentNum, NULL, NULL, &at);
    if(hr == S_OK)
    {
    ULONG ulInterfaceOptions=STGM_READ;
    ULONG ulFlags=0;
    LPSTREAM m_pStream;
    hr = at->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream, ulInterfaceOptions, ulFlags, (LPUNKNOWN*)&m_pStream);
    if(hr == S_OK)
    {
    BYTE buf[4096];
    int nRead;
    blobData = "";
    do 
    {
    nRead=0;
    ULONG ulRead;
    pictureData.clear();
    m_pStream->Read(buf, 4096, &ulRead);
    nRead=ulRead;
    if(nRead>0) 
    {
    string strbuf(reinterpret_cast<char const*>(buf), nRead);
    pictureData.append(strbuf);
    }
    }while (nRead>0);
    MAPIFreeBuffer(m_pStream);
    }
    }
    MAPIFreeBuffer(at);
    isOver=true;
    return TRUE;
    }
    break;
    }
    }
    }
    }
    }

    ***********************************************************************

    but i don't get image data.
    Tuesday, April 22, 2014 8:51 AM
  • i solved problem 

    my code is correct but issues in outlook 2007

    i reinstalled outlook 2007 again

    My problem solved ..

    Thanks again replay

     

    Tuesday, April 22, 2014 9:51 AM
  • Good news! Thank you for letting me know.

    > I don't use extended MAPI. i used core MAPI API.

    There is no core MAPI API. You use Extended MAPI functions ;-)

    Tuesday, April 22, 2014 10:48 AM
  • which one is  core MAPI API for outlook ?
    Tuesday, April 22, 2014 10:57 AM
  • Sorry, I don't know any core API. There are Simple and Extended MAPIs.
    Tuesday, April 22, 2014 2:13 PM