Skip to content

std.winrt

COM/WinRT init, activation, HSTRING; windows only (ole32, combase)

pub CO_MULTITHREADED :: 0
pub CO_APARTMENTTHREADED :: 2
pub CLSCTX_INPROC_SERVER :: 1

the usual context for co_create_instance

pub co_initialize :: fn(mode: u32) -> void ! ComError

this thread only; S_FALSE too owes a co_uninitialize on the same thread .changed_mode if the thread already initialised the other way

pub co_uninitialize :: fn()

undoes one co_initialize, same thread

pub co_create_instance :: fn(clsid: *const Guid, context: u32, iid: *const Guid, out: **void) -> i32

*out has one ref to release, null on failure; context is a CLSCTX value

pub co_task_mem_free :: fn(p: ?*void)

COM task allocator memory, e.g. the IInspectable.get_iids array

pub new_guid :: fn() -> Guid ! ComError

CoCreateGuid, random (RFC 4122 v4)

pub RO_SINGLETHREADED :: 0
pub RO_MULTITHREADED :: 1
pub ro_initialize :: fn(kind: i32) -> void ! ComError

this thread only; S_FALSE too owes a ro_uninitialize on the same thread .changed_mode if the thread already initialised the other way

pub ro_uninitialize :: fn()

undoes one ro_initialize, same thread

pub activation_factory :: fn(class_id: usize, iid: *const Guid) -> *IUnknown ! ComError

class_id is an HSTRING; owned ref, release it; .class_not_registered if unknown

pub activate_instance :: fn(class_id: usize) -> *IInspectable ! ComError

default ctor; owned ref

pub HString :: struct {
h: usize,
}

owned; release once, never release two copies of one

pub release :: fn(self: *Self)

safe to call twice or on an empty string

pub len :: fn(self: *const Self) -> usize

UTF-16 code units

pub is_empty :: fn(self: *const Self) -> bool
pub units :: fn(self: *const Self) -> []const u16

borrowed, valid until release(); no NUL in the slice

pub duplicate :: fn(self: *const Self) -> HString ! ComError

cheap second owned ref; release both

pub eq :: fn(self: *const Self, other: *const HString) -> bool

ordinal, case-sensitive

pub to_utf8 :: fn(self: *const Self, out: []u8) -> usize ! utf16::Utf16Error

.invalid_utf16 or .buffer_too_small; size it with utf16::utf8_len(self.units())

pub hstring :: fn(units: []const u16) -> HString ! ComError

owned copy, may be empty or hold zeros; .out_of_memory if the OS can’t allocate

pub hstring_from_utf8 :: fn(text: []const u8, scratch: []u16) -> HString ! utf16::Utf16Error

scratch needs utf16_len(text) units, free after; .invalid_utf8, .buffer_too_small

pub HStringRef :: struct {
header: [3]u64,
h: usize,
}

borrowed HSTRING, no alloc, nothing to release don’t move or copy after init(); the UTF-16 buffer must outlive h

  • header: HSTRING_HEADER, 24 bytes
  • h: the handle; valid after init()
pub init :: fn(self: *Self, z: []const u16) -> void ! ComError

z must end in one 0 unit (not part of the string), else .invalid_arg