Vérification du blocage d’une pièce jointe

S’applique à : Outlook 2013 | Outlook 2016

Cet exemple de code en C++ montre comment utiliser l’interface IAttachmentSecurity : IUnknown pour savoir si une pièce jointe est bloquée par Microsoft Outlook 2010 ou Microsoft Outlook 2013 pour l’affichage et l’indexation.

IAttachmentSecurity : IUnknown est dérivé de l’interface IUnknown . Vous pouvez obtenir l’interface IAttachmentSecurity : IUnknown en appelant IUnknown ::QueryInterface sur l’objet de session MAPI, en demandant IID_IAttachmentSecurity. IAttachmentSecurity ::IsAttachmentBlocked retourne true dans pfBlocked si la pièce jointe est considérée comme non sécurisée par Outlook 2010 ou Outlook 2013 et est bloquée pour l’affichage et l’indexation dans Outlook 2010 ou Outlook 2013.

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; 
}