How to: Verify an Attachment is Blocked

Last modified: October 10, 2010

Applies to: Office 2010 | Outlook 2010 | Visual Studio

This code sample in C++ shows how to use the IAttachmentSecurity : IUnknown interface to find out whether an attachment is blocked by Microsoft Outlook 2010 for viewing and indexing.

IAttachmentSecurity : IUnknown is derived from the IUnknown interface. You can obtain the IAttachmentSecurity : IUnknown interface by calling IUnknown::QueryInterface on the MAPI session object, requesting IID_IAttachmentSecurity. IAttachmentSecurity::IsAttachmentBlocked returns true in pfBlocked if the attachment is considered unsafe by Outlook 2010 and is blocked for viewing and indexing in Outlook 2010.

HRESULT IsAttachmentBlocked(LPMAPISESSION lpMAPISession, LPCWSTR pwszFileName, BOOL* pfBlocked) 
{ 
    if (!lpMAPISession || !pwszFileName || !pfBlocked) return MAPI_E_INVALID_PARAMETER; 
 
    HRESULT hRes = S_OK; 
    IAttachmentSecurity* lpAttachSec = NULL; 
    BOOL bBlocked = false; 
 
    hRes = lpMAPISession->QueryInterface(IID_IAttachmentSecurity,(void**)&lpAttachSec); 
    if (SUCCEEDED(hRes) && lpAttachSec) 
    { 
        hRes = lpAttachSec->IsAttachmentBlocked(pwszFileName,&bBlocked); 
    } 
    if (lpAttachSec) lpAttachSec->Release(); 
 
    *pfBlocked = bBlocked; 
    return hRes; 
}

Show:
© 2014 Microsoft