Microsoft KB Archive/288156

= How To Create an Exchange 2000 Store Event Sink in Visual C++ =

Article ID: 288156

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q288156



SUMMARY
This article demonstrates how to write a Store Event sink for Exchange Server 2000 by using Visual C++.



MORE INFORMATION
To create a Store Event sink, follow these steps. Note that you must do your development on an Exchange 2000 server.

 In Visual C++, create a new project. In the dialog box, select ATL COM AppWizard and accept the default settings. On the Insert menu, click New ATL Object. Select Simple Object and click Next. Type a name for the object, and then click OK. Click the ClassView tab to switch to the ClassView in your workspace browser. Right-click the class that was created, click Implement Interface, and then click OK. In the list of available type libraries, select EXOLEDB Type Library (1.0), and then click OK. In the Implement Interface dialog box, select the ones you want to implement and click OK. For store events, you must select at least one of the following interfaces:  IExStoreAsyncEvents: OnSave, OnDelete IExStoreSyncEvents: OnSyncSave, OnSyncDelete</li> IExStoreSystemEvents: OnMDBStartup, OnMDBShutdown, OnTimer</li></ul>

</li>  To avoid redefinition errors, rename the _SID_IDENTIFIER_AUTHORITY and the _SID structures in the EXOLEDB library. To do this, open the header file that was created for you, and change the following line to: rename (&quot;_SID_IDENTIFIER_AUTHORITY&quot;,&quot;EXOLEDB_SID_IDENTIFIER_AUTHORITY&quot;), rename(&quot;_SID&quot;,&quot;EXOLEDB_SID&quot;) </li>  You can now expand the class that was created and see the list of functions for the interfaces that you chose. Double-click a function to go to the function definition. These functions are in a header file, and are inline functions that return the COM return code that indicates that they have not been implemented. For example: STDMETHOD(OnSyncDelete)(IExStoreEventInfo * pEventInfo, BSTR bstrURLItem, LONG lFlags) {   return E_NOTIMPL; }                   </li> For the functions that you want to implement, remove the inline function, leaving just the function prototype. Be sure to end the prototype with a semicolon .</li>  Switch to the source (.cpp) file that matches the name of the header. Place your function implementations here. For example: // Import the ADO and CDOEX DLLs.
 * 1) import &quot;C:\Program Files\Exchsrvr\bin\exoledb.dll&quot; raw_interfaces_only, raw_native_types, no_namespace, named_guids
 * 1) import &quot;C:\Program Files\Exchsrvr\bin\exoledb.dll&quot; raw_interfaces_only, raw_native_types, no_namespace, named_guids,\
 * 1) import &quot;C:\Program Files\Common Files\system\ado\msado15.dll&quot; no_namespace rename(&quot;EOF&quot;,&quot;adoEOF&quot;), named_guids
 * 2) import &quot;C:\Program Files\Common Files\Microsoft Shared\CDO\cdoex.dll&quot; no_namespace

STDMETHODIMP CATLSink::OnSyncSave(IExStoreEventInfo * pEventInfo, BSTR bstrURLItem, LONG lFlags) {   HRESULT hr = S_OK;

// Only do this at the beginning of the transaction. if (lFlags & EVT_SYNC_BEGIN) {       // Cast pEventInfo to a IExStoreDispEventInfoPtr. IExStoreDispEventInfoPtr pDispInfo = pEventInfo; // Create a new message. IMessagePtr iMsg(__uuidof(Message)); _RecordPtr rec; char szSubject[256]; char szTextBody[256];

// Get the record that caused the event. // This is the new message. pDispInfo->get_EventRecord((IDispatch**)&rec);

// Set up a reply. iMsg->From = &quot;notifier@microsoft.com&quot;; // Set the recipient to the sender of the message that caused the event. iMsg->To = rec->Fields->GetItem(&quot;urn:schemas:httpmail:fromemail&quot;)->Value.bstrVal; // Set up the subject string to contain the subject of the message that caused the event. sprintf(szSubject,&quot;Message Received: %s&quot;, (char*)(_bstr_t)rec->Fields->GetItem(&quot;urn:schemas:httpmail:subject&quot;)->Value.bstrVal); iMsg->Subject = szSubject; // Set up the text of the message to contain the URL to the message that caused the event. sprintf(szTextBody, &quot;The following item was received:\n%s&quot;, (char*)(_bstr_t)bstrURLItem); iMsg->TextBody = szTextBody;

// Send the message. iMsg->Send;

iMsg = NULL; }   return hr; }                   </li> Compile and link your code. This automatically builds and registers a dynamic-link library (DLL). For the event sink to function, place the DLL in a COM+ application.</li></ol>

Keywords: kbhowto kbmsg KB288156

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.