Building Managed Event Sink DLLs

Building Managed Event Sink DLLs

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Building managed store event sink dynamic-link libraries (DLLs) consists of multiple steps, which are listed in the procedures below. After the event sink dynamic-link library (DLL) has been built, it must be wrapped in a COM+ application and registered on the server. See Creating a COM+ Event Sink Application and Event Registration for more information.

To register the managed event sink DLL for COM interop

  1. Create a new Microsoft® Visual Studio® .NET Class Library project.
  2. Select Project and then Project Properties. The Project Property Pages window comes up.
  3. Select Configuration Properties in the left window-pane and then select Build.
  4. If the event sink is to be used in debugging, select the Active(Debug) value of the Configuration drop-down menu. If the event sink is to be used in a production environment, select the Release value.
  5. Expand the Outputs section.
  6. Under Outputs, toggle the Register for COM Interop value to True. In the Microsoft Visual Basic® .NET Integrated Development Environment (IDE), check the Register for COM Interop checkbox. This will register the event sink assembly in the Microsoft Windows® registery and build a .TLB file when the project is built so that the event sink DLL can be used by COM+.
  7. Click OK

The Event Interfaces are implemented in exoledb.dll and a reference to the DLL must be added to the Visual Studio .NET project to implement the event sinks. A strong-named assembly must be built from exoledb.dll first, however, before the Event Interfaces can be used in a managed code application. This is done by using the Sn.exe tool to create a key pair for the new assembly and the TlbImp.exe tool to build the new assembly with the common language runtime equivilents of the Component Object Model (COM) type definitions. Both Sn.exe and TlbImp.exe are installed with the Microsoft .NET Framework software development kit (SDK) tools and are installed to the \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\ directory. See the .NET Framework SDK for more information on strong-named assemblies and the Sn.exe and TlbImp.exe tools.

To build a strong-named assembly from exoledb.dll

  1. Copy exoledb.dll from the \Program Files\Exchsrvr\bin\ directory on the Microsoft Exchange server to the Visual Studio .NET project directory on your development computer.
  2. Launch the Visual Studio .NET command prompt window and navigate to the Visual Studio .NET project directory.
  3. Type Sn.exe -k exoledb.snk in the command window to create a strong-named key.
  4. Type Tlbimp.exe exoledb.dll /keyfile:exoledb.snk /out:Interop.Exoledb.dll to build the strong-named assembly with the common language runtime equivalents of the COM type definitions in exoledb.dll. A warning about not being able to qualify the _SID.SubAuthority may be displayed and can be ignored.

The Store Event Sink Bit Flags are defined in exevtsnk.tlb and a reference to the .TLB must be added to the Visual Studio .NET project to implement the bit flags. A strong-named assembly must be built from exevtsnk.tlb first, however, before the Store Event Sink Bit Flags can be used in a managed code application. exevtsnk.tlb is installed with the Exchange Software Development Kit (SDK).

To build a strong-named assembly from exevtsnk.tlb

  1. Copy exevtsnk.tlb from the \Program Files\Exchange SDK\SDK\Support\OLEDB\ directory on the development computer to the Visual Studio .NET project directory on your development computer.
  2. Launch the Visual Studio .NET command prompt window and navigate to the Visual Studio .NET project directory.
  3. Type Sn.exe -k exevtsnk.snk in the command window to create a strong-named key.
  4. Type Tlbimp.exe exevtsnk.tlb /keyfile:exevtsnk.snk /out:Interop.Exevtsnk.dll to build the strong-named assembly with the common language runtime equivalents of the COM type definitions in exevtsnk.tlb. A warning about not being able to qualify the _SID.SubAuthority may be displayed and can be ignored.

References to the newly build Interop.Exoledb.dll and Interop.Exevtsnk.dll assemblies need to be added to the Visual Studio .NET project, as well as a references to the System.EnterpriseServices assembly. The System.EnterpriseServices assembly provides .NET assemblies with access to COM+ services making the .NET Framework objects more practical for enterprise applications.

To add project references

  1. In the Project menu, select Add Reference.
  2. Click the Browse button. The Select Component window opens.
  3. Navigate to the project directory and select Interop.Exoledb.dll and Interop.Exevtsnk.dll and click Open.
  4. Click OK in the Add Reference window to add these references to the project.
  5. In the Project menu, select Add Reference.
  6. Select the .NET tab and select System.EnterpriseServices from the components list.
  7. Click Select and then OK to add these references to the project.
  8. Add the following references to the top of the source code file. If it is Microsoft C#:
using System;
using System.Reflection;
using Exoledb = Interop.Exoledb;
using ExevtsnkLib = Interop.Exevtsnk;
using System.EnterpriseServices;

If it is Visual Basic .NET:

Imports System.EnterpriseServices
Imports Exoledb = Interop.Exoledb
Imports ExevtsnkLib = Interop.Exevtsnk
Imports System.Reflection

The event sink DLL needs to be built and signed with a strong name.

To build and sign the event sink DLL with a strong name

  1. Launch the Visual Studio .NET command window and navigate to the project output path. For example, the \bin\debug\ directory for C# or the \bin\ directory for Visual Basic .NET.

  2. Type Sn.exe -k EventSinkDLL.snk, where EventSinkDll is the name of the DLL, in the command window to create a strong-named key.

  3. Move the EventSinkDll.snk to the \obj\debug\ or \obj\release\ directory, depending on whether the project is being built in Debug or Release configuration.

  4. Double-click and open the AssemblyInfo file in the Solution Explorer pane of Visual Studio .NET.

  5. Add using System.EnterpriseServices; if it is C#, or Imports System.EnterpriseServices if it is Visual Basic .NET, to the top of AssemblyInfo file.

  6. At the bottom of AssemblyInfo add the following assembly attributes, where EventSinkDLL is the DLL name. If it is C#:

[assembly: AssemblyKeyFile("EventSinkDLL.snk")]
[assembly: AssemblyKeyName("EventSinkDLL")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationName("EventSinkDLL")]

If it is Visual Basic .NET:

<assembly: AssemblyKeyFile("EventSinkDLL.snk")>
<assembly: AssemblyKeyName("EventSinkDLL")>
<assembly: ApplicationActivation(ActivationOption.Server)>
<assembly: ApplicationName("EventSinkDLL")>

Implement the event sink interfaces and code. From the Build menu select Build Solution to build the event sink DLL.

The following asynchronous event sink function stubs can be used to get going quickly. For more detailed examples, see Implementing Synchronous Event Sinks, Implementing Asynchronous Event Sinks, and Implementing System Event Sinks.

Visual Basic.NET

Option Explicit On
Option Strict On

' Add project references to the System.EnterpriseServices,
' Interop.Exoledb.dll, and Interop.Exevtsnk.dll .NET components.
Imports System.EnterpriseServices
Imports Exoledb = Interop.Exoledb
Imports ExevtsnkLib = Interop.Exevtsnk
Imports System.Reflection

Namespace ExchangeSDK.Snippets.VBNet

Public Class AsyncEvents
   Inherits ServicedComponent
   Implements Exoledb.IExStoreAsyncEvents

   Public Sub OnDelete(ByVal pEventInfo As Interop.Exoledb.IExStoreEventInfo, _
                       ByVal bstrURLItem As String, _
                       ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreAsyncEvents.OnDelete

      ' Implement OnDelete code here.

   End Sub

   Public Sub OnSave(ByVal pEventInfo As Interop.Exoledb.IExStoreEventInfo, _
                     ByVal bstrURLItem As String, _
                     ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreAsyncEvents.OnSave

      ' Implement OnSave code here.

   End Sub
End Class
End Namespace

C#

// Add project references to the System.EnterpriseServices,
// Interop.Exoledb.dll, and Interop.Exevtsnk.dll .NET components.
using System;
using System.Reflection;
using Exoledb = Interop.Exoledb;
using ExevtsnkLib = Interop.Exevtsnk;
using System.EnterpriseServices;

namespace ExchangeSDK.Snippets.CSharp
{
   public class AsyncEvents : ServicedComponent, Exoledb.IExStoreAsyncEvents
   {
      public void OnDelete(Exoledb.IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags)
      {
         // Implement OnDelete code here.
      }

      public void OnSave(Exoledb.IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags)
      {
         // Implement OnSave code here.
      }
   }
}

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

This topic last updated: September 2004

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.