Microsoft KB Archive/304933

= How To Determine Which Outlook Object Caused an Exchange Client Extension Event to Fire =

Article ID: 304933

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 98 Standard Edition
 * Microsoft Office 97 Standard Edition

-



This article was previously published under Q304933



SUMMARY
This article describes how to identify which Outlook object caused an Exchange Client Extension event to fire. This article assumes that you already have an Exchange Client Extension that uses the Outlook Object Model and implements a function that passes you a pointer to an LPEXCHEXTCALLBACK interface such as OnRead or OnReadComplete. For information on creating an Exchange Client Extension that uses the Outlook Object Model, see the &quot;References&quot; section of this article.



MORE INFORMATION
The process to gain access to the item that caused the item to fire is as follows:
 * 1) Obtain a pointer to the Outlook application.
 * 2) Obtain an IDispatch pointer to the item that caused the event to fire.
 * 3) Access the type information to determine what type of object you have.
 * 4) Cast the IDispatch pointer to that type.

The following code implements this process in the OnRead event of an Exchange Client Extension: STDMETHODIMP MyMessageEvents::OnRead( LPEXCHEXTCALLBACK lpeecb) {   IOutlookExtCallback *pOutlook = NULL; LPDISPATCH lpMyDispatch = NULL; HRESULT hRes; BSTR szName;

//Get a pointer to the Outlook application. hRes = lpeecb->QueryInterface(IID_IOutlookExtCallback, (void **) &pOutlook); if (pOutlook) {       //Get an IDispatch pointer to the item that caused the event to fire. IUnknown *pUnk = NULL; pOutlook->GetObject(&pUnk); if (pUnk != NULL) {           hRes = pUnk->QueryInterface(IID_IDispatch, (void **) &lpMyDispatch); pUnk->Release; }   }    if (lpMyDispatch) {       //Get type information LPTYPEINFO lpMyTypeInfo = NULL; hRes = lpMyDispatch->GetTypeInfo(0, 0, &lpMyTypeInfo); if (lpMyTypeInfo != NULL) hRes = lpMyTypeInfo->GetDocumentation(MEMBERID_NIL, &szName, 0, 0, 0);

//Display the item type. MessageBox(NULL,(char *)(_bstr_t)szName,&quot;Item Type&quot;,MB_OK); }

if (0 == strcmp(&quot;_MailItem&quot;,(char *) (_bstr_t)szName)) //Check to see if item is a Mail Item. {       //Cast the IDispatch pointer to a MailItem pointer _MailItemPtr MailItem = lpMyDispatch;

//Display Message Class. MessageBox(NULL, (char*)MailItem->MessageClass, &quot;Message Class&quot;, MB_OK); }

if (lpMyDispatch) lpMyDispatch->Release; if (pOutlook) pOutlook->Release;

return S_FALSE; }

