Implement ObjectControl Interface to Use GetObjectContext()

Implement ObjectControl Interface to Use GetObjectContext()

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.

See also  Does It Make Sense to Splurge on a Laptop?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist