Microsoft Chat Server Development Guide

Event Binding

At system initialization or when restarted, no callback bindings exist. It is the extension's responsibility to register for events in which it is interested. Bindings can be performed on new objects at the time they are created. For instance, you can register for further ChatChannel events during an OnNewChannel event notification.

The IChatRegistrar object simplifies the registration process. A reference to the global IChatRegistrar object is passed to the extension during the IChatExtensionCallback::Init method. (For an example of this method, see Generic Bindings.) In order to bind to events during other methods, extension writers need to keep a reference to the IChatRegistrar object in a global variable.

The following Visual Basic example demonstrates how to use the IChatRegistrar::AddUserEvent method to add a dynamic binding for the OnAwayChanged user event during the OnAddMember notification, a previously bound channel event:

Function IChatChannelCallBack_OnAddMember ( _
   ByVal Channel As CHATSVCLib.IChatChannel, _
   ByVal User As CHATSVCLib.IChatUser, _
   ByVal PostUpdate As Boolean) As Long

   ' Bind only if user has already joined the channel
   If PostUpdate = True And Channel.Name = "#monitored" Then
      g_Registrar.AddUserEvent "OnAwayChanged", User
   End If

   IChatChannelCallBack_OnAddMember = 0
End Function

In the preceding example, the post-update OnAddMember event notification informs the extension that a user has been added to the channel. In response, the extension uses its global reference to the IChatRegistrar object to bind to the OnAwayChanged event for this user. In this case, the extension performs the binding only after the user successfully joins the "#monitored" channel.


© 1998 Microsoft Corporation. All rights reserved.