How To Determine Which Outlook Object Caused an Exchange Client Extension Event to Fire (304933)



The information in this article applies to:

  • Microsoft Outlook 2002
  • Microsoft Outlook 98 8.5
  • Microsoft Office 97 for Windows

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 "References" 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,"Item Type",MB_OK);
	}


	if (0 == strcmp("_MailItem",(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, "Message Class", MB_OK);
	}

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

	return S_FALSE;
}
				

REFERENCES

286408 Microsoft Outlook and Exchange Client Extensions

NOTE: The preceding reference is to a Microsoft White Paper

285999 How To Build a Minimal Exchange Client Extension with VC++

199343 INFO: The Basics of Exchange Client Extensions


Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbhowto kbMsg KB304933