Figure 12   Publisher Event Firing

' Create the event class object

Dim foo As New StockEventCls

' Call the event class object's method that
' fires the StockPriceChanged event.

Private Sub Command1_Click()
    Call foo.StockPriceChanged(Text1.Text, CCur(Text2.Text))
End Sub

' Call the event class object's method that
' fires the NewStockListed event.

Private Sub Command2_Click()
    Call foo.NewStockListed(Text1.Text)
End Sub

Figure 13   Receiving an Event Notification


' The subscriber must implement the interface on
' which it wants to receive calls from the event object

Implements StockEventCls

' Pop up message box telling user of
' NewStockListed event

Private Sub StockEventCls_NewStockListed(ByVal Symbol As String)
    MsgBox "New Stock " + Symbol + " has started trading", vbOKOnly, _
        "VB Event Subscriber"
End Sub

' Pop up message box telling user of
' StockPriceChanged event

Private Sub StockEventCls_StockPriceChanged(ByVal Symbol As String, _
                                            ByVal Price As Currency)
    MsgBox "The market price of stock " + Symbol + " is now " + Str(Price), _
        vbOKOnly, "VB Event Subscriber"
End Sub

Figure 14   IEventSubscription Interface

Method/Property
Description
SubscriptionID
Unique identifier for this subscription within the event system.
SubscriptionName
Human-readable name for this subscription.
PublisherID
Unique identifier of publisher required by the subscription. If NULL, subscription accepts events from any publisher.
EventClassID
Exact event class that the subscription requires. Supported for backward compatibility, and generally ignored by subscribers in favor of the InterfaceID property.
MethodName
Name of the method from which the subscriber wants to receive incoming event calls. Specified relative to the InterfaceID.
SubscriberCLSID
COM+ component identifier of the subscriber. Used by the event class to create the subscriber object.
SubscriberInterface
Actual IUnknown pointer to the interface on which the subscriber wants to receive incoming event calls. Used for transient subscriptions.
PerUser
When set to TRUE, the subscription only receives events when the user identified by the OwnerSID property is logged in.
OwnerSID
Security credential of a program that creates a subscription.
Enabled
Turns the delivery of events to the subscription on or off.
Description
Unused by the event system. Available as a comment field for subscribers or administrators.
MachineName
Name of the machine on which the subscription resides.
PublisherProperty
A bag of properties set by the subscriber. A publisher filter can examine the contents of the bag to decide whether to fire an event to the subscriber or to customize the information delivered to the subscriber.
SubscriberProperty
Reserved for future use.
InterfaceID
Interface on which the subscriber wants to receive incoming event notifications.
FilterCriteria
String used for filtering events at the event class. Calls whose parameters do not match the string are not forwarded to the subscriber.
Subsystem
Reserved for future use.
SubscriberMoniker
Moniker to use when activating a subscriber.


Figure 15   Event Method Return Codes

Return Code
Description
S_OK
An event was able to successfully invoke all of the subscribers.
EVENT_S_SOME_SUBSCRIBERS_FAILED
An event was able to successfully invoke some, but not all, of the subscribers.
EVENT_E_ALL_ SUBSCRIBERS_FAILED
An event was unable to successfully invoke any of the subscribers.
EVENT_S_ NOSUBSCRIBERS
An event was fired but there were no subscribers.


Figure 17   IEventControl Methods

Name
Description
SetPublisherFilter
Allows the publisher to specify the desired filter class at runtime rather than at registration time.
get_AllowInprocActivation
put_AllowInprocActivation
Allows the publisher to override the administrative in-proc activation setting at runtime.
GetSubscriptions
Returns a self-updating collection of subscriptions to a specified method.
SetDefaultQuery
Sets the filter criteria to use on a specified method when a publisher filter is not installed.


Figure 18   IPublisherFilter Methods

Name
Description
Initialize
Called by the event system when the filter object is first created. Passes IEventControl for the filter to use.
PrepareToFire
Called by the event system to tell the filter object to examine its collection of subscriptions and fire the ones that it decides should be fired.