MTx.SafeRef Method

Used by an object to obtain a reference to itself that's safe to pass outside its context.

SafeRef is a static method of the MTx class, which is declared in the package com.ms.mtx.

Note The class MTx has only static methods and has no public constructor. You can't create an instance of this class.

IUnknown SafeRef (

IUnknown obj

);

Parameter

obj
[in] A reference to an interface on the current object.

Return Value

A reference to the IUnknown interface on the current object that's safe to pass outside the current object's context.

Remarks

When an MTS object wants to pass a self-reference to a client or another object (for example, for use as a callback), it should always call SafeRef first and then pass the reference returned by this call. An object should never pass a reference to this to a client or to any other object. Once such a reference is passed outside the object's context, it's no longer a valid reference.

Regardless of the interface ID you pass to SafeRef, it always returns the IUnknown interface on the object that calls it. You should immediately cast the returned value to the interface that you want to pass outside the object.

Calling SafeRef on a reference that is already safe returns the safe reference unchanged, except that the reference count on the interface is incremented.

Example

See Also

Passing Object References


© 1997 Microsoft Corporation. All rights reserved.