You Dirty Rat
[This is now documented here: https://msdn.microsoft.com/en-us/library/gg262878.aspx ]
Another in the series of APIs Development asked me to document. This time, it’s a property you can request via IDispatch to ask if an item is dirty or not. Same as last time, I didn’t test this code, so I’d appreciate feedback.
dispidFDirty
This property is used to tell if an Outlook item (such as a MailItem or ContactItem) is in the Dirty state. An item is considered Dirty when it has unsaved changes.
Syntax
Given an item pointer, use QueryInterface to obtain an IDispatch interface pointer. Then call IDispatch::Invoke with dispidFDirty and the flags DISPATCH_METHOD | DISPATCH_PROPERTYGET.
Sample Code
#define dispidFDirty 0xF024
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;
}
Comments
Anonymous
August 16, 2010
Can you force Outlook to think an item is not dirty using the same method (DISPATCH_PROPERTYSET)?Anonymous
August 16, 2010
Good question! Let us know what you find. :)Anonymous
August 16, 2010
Is this different from the existing MailItem Saved property?Anonymous
August 16, 2010
Nope. Raises DISP_E_EXCEPTION - "Property is read-only". Bummer...Anonymous
August 16, 2010
Setting the property doesn't work, Outlook throws an error.Anonymous
August 16, 2010
RE: MailItem Saved - I would assume it's different. Note that this dispid can be invoked against any item type.Anonymous
August 17, 2010
It looks like Saved and dispidFDirty return the same value in all cases. Also, Saved property is exposed by all the Item objects (MaiulItem, ContactItem, etc), not just MailItem. What makes dispidFDirty different from Saved?Anonymous
August 17, 2010
I think you mean it returns the opposite value in all cases, correct? :) As far as I can tell, one is the inverse of the other.Anonymous
August 18, 2010
Yes, I meant that they are consistently the opposite of each other.Anonymous
July 23, 2017
HI Stephen,My requirement is ,in my vsto plugin for outlook, when user open any mail (by double click on mail item), I modify the attachments of that mail. I dont want to save these changes on server / disk thats why I am not saving the mail item.My problem is when I try to close this read window, outlook asks that "attachment has been modified for mail, would you like to save it". How can I suppress / avoid this message.DispIDDirty and saved property of MailItem is read only. I have also tried following code :--((ItemEvents_10_Event)WrappedObject).Close += HandleEvent_MailItem_Close; private void HandleEvent_MailItem_Close(ref bool Cancel) { WrappedObject.Close(OlInspectorClose.olDiscard); }But instead of discarding, it has started saving mail item. Is this a bug in outlook ? Do we have any work around for that ?