This documentation is archived and is not being maintained.


This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Opens an attachment.

HRESULT OpenAttach(
  ULONG ulAttachmentNum,
  LPCIID lpInterface,
  ULONG ulFlags,
  LPATTACH FAR * lppAttach


[in] Index number of the attachment to open, as stored in the attachment's PR_ATTACH_NUM (PidTagAttachNumber) property. This index number uniquely identifies the attachment in the message and is valid only in the context of the message.


[in] Pointer to the interface identifier (IID) representing the interface to be used to access the attachment. Passing NULL results in the attachment's standard interface, or IAttach, being returned.


[in] Bitmask of flags that controls how the attachment is opened. The following flags can be set:


Requests that the attachment be opened with the maximum network permissions allowed for the user and the maximum client application access. For example, if the client has read/write permission, the attachment should be opened with read/write permission; if the client has read-only access, the attachment should be opened with read-only access.


Allows OpenAttach to return successfully, possibly before the attachment is fully available to the calling client. If the attachment is not available, making a subsequent call to it can cause an error.


Requests read/write permission. By default, attachments are opened with read-only access, and clients should not work on the assumption that read/write permission has been granted.


[out] Pointer to a pointer to the open attachment.


The attachment was successfully opened.

The IMessage::OpenAttach method opens a message's attachment.

To open an attachment, you must have access to its attachment number or PR_ATTACH_NUM property. Call IMessage::GetAttachmentTable to retrieve the message's attachment table and locate the row that represents the attachment to be opened. See Opening an Attachment for more information.

Do not try to open one attachment multiple times; the results are undefined and dependent on the message store provider.

You can request that the attachment be opened in read/write mode, instead of the default read-only mode. However, whether the attachment will actually be opened in read/write mode is up to the message store provider. You can either attempt to modify the attachment, preparing to handle possible failure, or check the level of access that was granted by retrieving the attachment's PR_ACCESS_LEVEL (PidTagAccessLevel) property, if it is available.

For MFCMAPI sample code, see the following table.




AttachmentsDlg.cpp Used to


MFCMAPI uses the IMessage::OpenAttach method to open attachment objects,