How to uniquely identify explorer / inspector objects in Outlook 2007

  • Thread starter Thread starter gernot
  • Start date Start date
G

gernot

I am always getting different interface pointers for same explorer
objects. The same happens for inspector objects. What can a do to
unquely identify these objects?

Scenario:

1. In the NewInspector handler I save the _Inspector pointer.
2. In an event handler from a control in this inspector I use
IRibbonControl::get_Context() to obtain the corresponding _Inspector
pointer.

These pointers are never the same (comparing IUnknown pointers). These
COM objects are not the same!

In the case of inspectors I get away identifying them by its creation
date.
What can I do to identify explorers? Is there any Outlook method to
compare these objects?

Thanks, Gernot
 
Outlook 2007 allows you to test for equality of two Inspector or Explorer
objects using the C# == operator or the VB Is operator. Earlier versions of
Outlook don't allow that.

What I usually do is to test for the window.Caption and also for the window
rectangle dimensions and coordinates. I use the Explorer (or Inspector) Top,
Left, Height and Width properties compared to the window I get using
FindWindow (a Win32 API call). If it's the foreground window you're working
with you can use GetForegroundWindow instead of using FindWindow.
 
How does C# implement the == operator? It must be more than just
comparing COM objects.
The workaround with FindWindow() is alright ;-)

Thanks, Gernot
 
It's just a comparison of the COM objects, just a normal C# equality
comparison. It's just that the Outlook team fixed Explorers and Inspectors
so that works in Outlook 2007.
 
Finally I compare inspector objects by their entry id:

_Inspector *pInspector;

// get entry id
CComPtr<IDispatch> pDispCurrentItem;
HRESULT hr = pInspector->get_CurrentItem(&pDispCurrentItem);
if (FAILED(hr)) { ReportError(hr); return NULL; }

CComQIPtr<_MailItem> pMailItem(pDispCurrentItem);
if (!pMailItem) { ReportError(E_POINTER); return NULL; }

CComPtr<IUnknown> pUnkMessage;
hr = pMailItem->get_MAPIOBJECT(&pUnkMessage);
if (FAILED(hr)) { ReportError(hr); return NULL; }

CComQIPtr<IMessage, &IID_IMessage> pMessage(pUnkMessage);
if (!pMessage) { ReportError(E_POINTER); return NULL; }

SPropValue *pProp = NULL;
hr = HrGetOneProp(pMessage, PR_ENTRYID, &pProp);
if (FAILED(hr)) { ReportError(hr); return NULL; }

Now pProp->Value.bin has the entry id. To check if two entry ids are
equal:

// get compare function
CComPtr<_NameSpace> pSession;
hr = pInspector->get_Session(&pSession);
if (FAILED(hr)) { ReportError(hr); return NULL; }

CComPtr<IUnknown> pUnkSession;
pSession->get_MAPIOBJECT(&pUnkSession);
if (FAILED(hr)) { ReportError(hr); return NULL; }

CComQIPtr<IMAPISession, &IID_IMAPISession>
pMAPISession(pUnkSession);
if (!pMAPISession) { ReportError(E_POINTER); return NULL; }

pMAPISession->CompareEntryIDs() is used to compare ids.

Comparing the IUnknown pointers of two _Inspector interfaces does not
work for C++.
 
MAPI entry ids may not exist before the item is saved. In this case I
use the creation time to identify the item.
 
Back
Top