Export (0) Print
Expand All

How to: Determine Whether an Outlook Item Has Been Modified but Not Saved (Outlook 2010 Auxiliary Reference)

Last modified: October 08, 2010

Applies to: Office 2007 | Office 2010 | Outlook 2010

This topic shows how to use the dispidFDirty dispatch ID to invoke the corresponding property on a Microsoft Outlook item, to see whether the item has been modified and has not been saved.

Given an item object, you can use the IUnknown::QueryInterface method to obtain an IDispatch interface pointer. The function in this topic, FIsItemDirty, accepts an IDispatch pointer, pdisp, as an input parameter. FIsItemDirty calls the IDispatch::Invoke method, specifying dispidFDirty as the argument for the dispIdMember parameter, and the flags DISPATCH_METHOD | DISPATCH_PROPERTYGET for wFlags, to verify whether the item has been modified. FIsItemDirty returns a Boolean value (True to indicate that the item has unsaved changes; otherwise, False).

bool FIsItemDirty(IDispatch *pdisp)
{
    DISPPARAMS dispparams;
    UINT uArgErr;
    HRESULT hr = S_OK;
    CComVariant varDirty;
    dispparams.rgvarg = 0;
    dispparams.cArgs = 0;
    dispparams.cNamedArgs = 0;
    dispparams.rgdispidNamedArgs = NULL;
    hr = pdisp->Invoke(dispidFDirty,
        IID_NULL,
        LOCALE_SYSTEM_DEFAULT,
        DISPATCH_METHOD | DISPATCH_PROPERTYGET,
        &dispparams,
        &varDirty,
        NULL,
        &uArgErr);
    return SUCCEEDED(hr) && varDirty.bVal;
}

Show:
© 2014 Microsoft