#[repr(C)]pub struct ComPtr<T>(_);
Expand description
Smart pointer for Windows Runtime objects. This pointer automatically maintains the reference count of the underlying COM object.
Implementations§
source§impl<T> ComPtr<T>
impl<T> ComPtr<T>
sourcepub unsafe fn wrap(ptr: *mut T) -> ComPtr<T>
pub unsafe fn wrap(ptr: *mut T) -> ComPtr<T>
Creates a ComPtr
to wrap a raw pointer.
It takes ownership over the pointer which means it does not call AddRef
.
T
must be a COM interface that inherits from IUnknown
.
The wrapped pointer must not be null.
sourcepub unsafe fn wrap_optional(ptr: *mut T) -> Option<ComPtr<T>>
pub unsafe fn wrap_optional(ptr: *mut T) -> Option<ComPtr<T>>
Creates an optional ComPtr
to wrap a raw pointer that may be null.
It takes ownership over the pointer which means it does not call AddRef
.
T
must be a COM interface that inherits from IUnknown
.
sourcepub unsafe fn into_unchecked<Interface>(self) -> ComPtr<Interface>where
Interface: ComInterface,
pub unsafe fn into_unchecked<Interface>(self) -> ComPtr<Interface>where
Interface: ComInterface,
Changes the type of the underlying COM object to a different interface without doing QueryInterface
.
This is a runtime no-op, but you need to be sure that the interface is compatible.
sourcepub fn get_runtime_class_name(&self) -> HStringwhere
T: RtClassInterface,
pub fn get_runtime_class_name(&self) -> HStringwhere
T: RtClassInterface,
Gets the fully qualified name of the current Windows Runtime object.
This is only available for interfaces that inherit from IInspectable
and
are not factory or statics interfaces.
Examples
Basic usage:
use winrt::*;
use winrt::windows::foundation::Uri;
let uri = FastHString::new("https://www.rust-lang.org");
let uri = Uri::create_uri(&uri).unwrap();
assert_eq!("Windows.Foundation.Uri", uri.get_runtime_class_name().to_string());
sourcepub fn query_interface<Target>(&self) -> Option<ComPtr<Target>>where
Target: ComIid,
T: ComInterface,
pub fn query_interface<Target>(&self) -> Option<ComPtr<Target>>where
Target: ComIid,
T: ComInterface,
Retrieves a ComPtr
to the specified interface, if it is supported by the underlying object.
If the requested interface is not supported, None
is returned.