Get binaries of attachments

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
How can I get attachment binary data without saving it on a file?
I try with the following code but HrGetOneProp give me E_OUTOFMEMORY if the
attachment is 670 KB.

HRESULT GetAttachmentBinaryProp(Outlook::Attachment *atch, std::vector<byte>
&binProp)
{
if (!atch)
return E_FAIL;
HRESULT hr;
CComQIPtr<Outlook::Attachment> attachment(atch);
CComPtr<IUnknown> mapiObj;
hr = attachment->get_MAPIOBJECT(&mapiObj);
if (FAILED(hr))
return hr;
LPSPropValue lpProps = NULL;
hr = HrGetOneProp((LPMAPIPROP)(IUnknown*)mapiObj, PR_ATTACH_DATA_BIN,
&lpProps);
if( lpProps && lpProps->ulPropTag==ulPropTag && lpProps->Value.bin.cb )
{
memcpy(&binProp[0], lpProps->Value.bin.lpb, binProp.size());
return S_OK;
} else
{
return E_FAIL;
}
}

Everything works well if the attachment is little (e.g. 4 KB).
Could anyone help me?
Thanks
Sektor
 
All (potentially) large string or binary propeties (such for PR_BODY and
PR_RTF_COMPRESSED for the messages or PR_ATTACH_DATA_BIN for attachments)
must be opened as an IStream (mapiObj->OpenProperty(PR_ATTACH_DATA_BIN,
&IID_IStream, ...)).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks.
Sektor.

Dmitry Streblechenko said:
All (potentially) large string or binary propeties (such for PR_BODY and
PR_RTF_COMPRESSED for the messages or PR_ATTACH_DATA_BIN for attachments)
must be opened as an IStream (mapiObj->OpenProperty(PR_ATTACH_DATA_BIN,
&IID_IStream, ...)).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi all,
How can I get attachment binary data without saving it on a file?
I try with the following code but HrGetOneProp give me E_OUTOFMEMORY if
the attachment is 670 KB.

HRESULT GetAttachmentBinaryProp(Outlook::Attachment *atch,
std::vector<byte> &binProp)
{
if (!atch)
return E_FAIL;
HRESULT hr;
CComQIPtr<Outlook::Attachment> attachment(atch);
CComPtr<IUnknown> mapiObj;
hr = attachment->get_MAPIOBJECT(&mapiObj);
if (FAILED(hr))
return hr;
LPSPropValue lpProps = NULL;
hr = HrGetOneProp((LPMAPIPROP)(IUnknown*)mapiObj, PR_ATTACH_DATA_BIN,
&lpProps);
if( lpProps && lpProps->ulPropTag==ulPropTag &&
lpProps->Value.bin.cb )
{
memcpy(&binProp[0], lpProps->Value.bin.lpb, binProp.size());
return S_OK;
} else
{
return E_FAIL;
}
}

Everything works well if the attachment is little (e.g. 4 KB).
Could anyone help me?
Thanks
Sektor
 
Back
Top