Get binaries of attachments

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
 
D

Dmitry Streblechenko

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
 
G

Guest

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
 

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