devxlogo

Pass MTS Object References Safely Between Processes

Pass MTS Object References Safely Between Processes

SafeRef returns a reference to the context wrapper instead of a reference to the object itself. You should never pass a direct reference of a Microsoft Transaction Server (MTS) object to a client application. If you do, the client application can make a call on the MTS object without going through the context wrapper. This defeats the interception scheme set up by the MTS runtime. You should use the SafeRef function, which returns the outside world’s view of an MTS object. Let’s say you’re writing a method implementation for an MTS object. In the method, you want to create an object of some class, then pass your own reference to the newly created object. To do this, you might write this code:

 Dim pSomeClass As CSomeClass Set pSomeClass = New CSomeClasspSomeClass.SomeMethod Me ' Incorrect code

However, this code is incorrect under MTS. The child object?pSomeClass?can invoke method calls on your object without going through the context wrapper. You should never bypass the interception scheme set up by the MTS runtime. Instead, you should pass a reference to your object:

 pSomeClass.SomeMethod SafeRef(Me)' Correct code

By calling SafeRef, you allow the child object to establish a connection that passes through the context wrapper. This technique keeps things in line with what the MTS runtime expects. The Me keyword is the only valid parameter you can pass when calling SafeRef with Visual Basic.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

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