A Visual Basic class module provides an Initialize procedure. The code you write in Initialize is executed when the Visual Basic object is created. However, Initialize is always executed before the object has been activated. This means that you can't successfully call GetObjectContext in Initialize. A call to GetObjectContext in Initialize won't experience a runtime error--it will simply return a null reference. However, you will get a runtime error, when you try to access a property or a method using this null reference.
The Terminate procedure in a Visual Basic class is executed prior to the object's destruction and after the object has been deactivated. Terminate is similar to Initialize in that you can't successfully call GetObjectContext in this procedure. These two procedures supplied by Visual Basic don't give you all the control you need to manage your object's life cycle in the MTS environment.
The MTS run time can help by notifying your object just after activation and once again just before deactivation. The MTS type library includes a definition for an interface named ObjectControl. When the MTS run time creates an MTS object, it calls QueryInterface to determine whether the object supports this interface. If an MTS object implements ObjectControl, the MTS run time calls methods in this interface to notify the object at important transition stages during its life cycle. This means that you should implement ObjectControl in every object that needs to receive these notifications. The ObjectControl interface contains the three methods: Activate, Deactivate, and CanBePooled. Activate is called by the MTS run time after activation and just before the first method call is executed. Deactivate is called by the MTS run time just before the object is switched out of the context wrapper. CanBePooled is called by the MTS run time after deactivation and just before the object is destroyed. To receive these notifications, you should implement the ObjectControl interface in the MultiUse class modules in your ActiveX DLLs.