XRPtr<Interface> (Windows Embedded CE 6.0)

1/6/2010

An XRPtr<Interface> object encapsulates a COM interface pointer to a Silverlight object and is called a "smart pointer." This template class manages reference count and lifetime ownership for object pointers through calls to the IUnknown member functions QueryInterface, AddRef, and Release.

Syntax

template<typename Interface> class XRPtr

Methods

Method Description

XRPtr<Interface>::AddRef

Calls the AddRef method of IUnknown on the encapsulated interface pointer.

XRPtr<Interface>::Attach

Encapsulates a raw interface pointer in this smart pointer's type.

XRPtr<Interface>::Detach

Extracts and returns the encapsulated interface pointer, and relinquishes ownership so that the returned interface will not be released by this smart pointer.

XRPtr<Interface>::Release

Calls the Release method of IUnknown on the encapsulated interface pointer.

Operators

Operator Description

XRPtr<Interface>::operator ->

Assigns a new value to an existing XRPtr<Interface> object.

XRPtr<Interface>::operator &

Returns the address of the interface pointer contained in this class.

XRPtr<Interface>::operator =

Either sets the interface pointer, copies the interface pointer and increments the reference count, or allows for the assignment of NULL to the class.

Remarks

Smart pointers manage the reference count of an object. A smart pointer will automatically call IUnknown::Release when the smart pointer goes out of scope.

We recommend that you use smart pointers when you call methods that pass IXRDependencyObject-derived objects in Silverlight for Windows Embedded, instead of explicitly calling IUnknown::QueryInterface to convert a generic interface into the required object type.

All objects in Silverlight for Windows Embedded have smart pointer aliases declared for them. For example, to create a smart pointer instead of a raw interface pointer to IXRButton, you can create a smart pointer of type IXRButtonPtr. You can also create a smart pointer by using the template class type XRPtr<XRButton>.

The following example code creates a smart pointer by using a smart pointer alias:

IXRButtonPtr pButton;
pApplication->CreateObject(&pButton);

The following example code creates a smart pointer by using the template class:

XRPtr<XRButton> pButton;
pApplication->CreateObject(&pButton);

Requirements

Header XRPtr.h
sysgen SYSGEN_XAML_RUNTIME
Windows Embedded CE Windows Embedded CE 6.0 R3

See Also

Reference

Classes for Application Management

Concepts

Type-Safety in Silverlight for Windows Embedded