std.com
COM/WinRT types as data (GUID, HRESULT, IUnknown, vtables); no OS calls out-pointers carry one ref, release exactly once; lent pointers aren’t yours
pub Guid :: struct { data1: u32, data2: u16, data3: u16, data4: [8]u8,}–– GUID –– 16 bytes, align 4; IIDs and CLSIDs are GUIDs
Guid.eq
Section titled “Guid.eq”pub eq :: fn(self: *const Self, other: *const Guid) -> boolGuid.is_null
Section titled “Guid.is_null”pub is_null :: fn(self: *const Self) -> boolall zero (GUID_NULL)
Guid.format
Section titled “Guid.format”pub format :: fn(self: *const Self, out: []u8) -> usize ! GuidErrorupper-case “{8-4-4-4-12}” into out, returns 38; .buffer_too_small if shorter
GUID_TEXT_LEN
Section titled “GUID_TEXT_LEN”pub GUID_TEXT_LEN :: 38text form length, with braces
GuidError
Section titled “GuidError”pub GuidError :: errors { invalid_format, buffer_too_small,}invalid_format: not 8-4-4-4-12 hex, braces optionalbuffer_too_small: the output buffer is shorter than GUID_TEXT_LEN
parse_guid
Section titled “parse_guid”pub parse_guid :: fn(text: []const u8) -> Guid ! GuidErrorstrict 8-4-4-4-12 hex, either case, braces optional; no spaces or extra text
IID_IUnknown
Section titled “IID_IUnknown”pub IID_IUnknown : Guid : .{ 0x00000000, 0x0000, 0x0000, .{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } } :: …IID_IInspectable
Section titled “IID_IInspectable”pub IID_IInspectable : Guid : .{ 0xAF86E2E0, 0xB12D, 0x4C6A, .{ 0x9C, 0x5A, 0xD7, 0xAA, 0x65, 0x10, 0x1E, 0x90 } } :: …IID_IAgileObject
Section titled “IID_IAgileObject”pub IID_IAgileObject : Guid : .{ 0x94EA2B94, 0xE9CC, 0x49E0, .{ 0xC0, 0xFF, 0xEE, 0x64, 0xCA, 0x8F, 0x5B, 0x90 } } :: …IID_IActivationFactory
Section titled “IID_IActivationFactory”pub IID_IActivationFactory : Guid : .{ 0x00000035, 0x0000, 0x0000, .{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } } :: …Hresult
Section titled “Hresult”pub Hresult :: i32–– HRESULT –– bit 31 failure, bits 16-26 facility, bits 0-15 code; values from winerror.h
pub S_OK :: 0S_FALSE
Section titled “S_FALSE”pub S_FALSE :: 1E_NOTIMPL
Section titled “E_NOTIMPL”pub E_NOTIMPL :: -2147467263E_NOINTERFACE
Section titled “E_NOINTERFACE”pub E_NOINTERFACE :: -2147467262E_POINTER
Section titled “E_POINTER”pub E_POINTER :: -2147467261E_ABORT
Section titled “E_ABORT”pub E_ABORT :: -2147467260E_FAIL
Section titled “E_FAIL”pub E_FAIL :: -2147467259E_UNEXPECTED
Section titled “E_UNEXPECTED”pub E_UNEXPECTED :: -2147418113E_OUTOFMEMORY
Section titled “E_OUTOFMEMORY”pub E_OUTOFMEMORY :: -2147024882E_INVALIDARG
Section titled “E_INVALIDARG”pub E_INVALIDARG :: -2147024809E_ACCESSDENIED
Section titled “E_ACCESSDENIED”pub E_ACCESSDENIED :: -2147024891E_HANDLE
Section titled “E_HANDLE”pub E_HANDLE :: -2147024890E_PENDING
Section titled “E_PENDING”pub E_PENDING :: -2147483638E_BOUNDS
Section titled “E_BOUNDS”pub E_BOUNDS :: -2147483637E_CHANGED_STATE
Section titled “E_CHANGED_STATE”pub E_CHANGED_STATE :: -2147483636E_ILLEGAL_METHOD_CALL
Section titled “E_ILLEGAL_METHOD_CALL”pub E_ILLEGAL_METHOD_CALL :: -2147483634RPC_E_CHANGED_MODE
Section titled “RPC_E_CHANGED_MODE”pub RPC_E_CHANGED_MODE :: -2147417850REGDB_E_CLASSNOTREG
Section titled “REGDB_E_CLASSNOTREG”pub REGDB_E_CLASSNOTREG :: -2147221164CO_E_NOTINITIALIZED
Section titled “CO_E_NOTINITIALIZED”pub CO_E_NOTINITIALIZED :: -2147221008CLASS_E_NOAGGREGATION
Section titled “CLASS_E_NOAGGREGATION”pub CLASS_E_NOAGGREGATION :: -2147221232CLASS_E_CLASSNOTAVAILABLE
Section titled “CLASS_E_CLASSNOTAVAILABLE”pub CLASS_E_CLASSNOTAVAILABLE :: -2147221231FACILITY_NULL
Section titled “FACILITY_NULL”pub FACILITY_NULL :: 0FACILITY_RPC
Section titled “FACILITY_RPC”pub FACILITY_RPC :: 1FACILITY_STORAGE
Section titled “FACILITY_STORAGE”pub FACILITY_STORAGE :: 3FACILITY_ITF
Section titled “FACILITY_ITF”pub FACILITY_ITF :: 4FACILITY_WIN32
Section titled “FACILITY_WIN32”pub FACILITY_WIN32 :: 7FACILITY_WINDOWS
Section titled “FACILITY_WINDOWS”pub FACILITY_WINDOWS :: 8succeeded
Section titled “succeeded”pub succeeded :: fn(hr: i32) -> boolfailed
Section titled “failed”pub failed :: fn(hr: i32) -> boolfacility
Section titled “facility”pub facility :: fn(hr: i32) -> u32pub code :: fn(hr: i32) -> u32from_win32
Section titled “from_win32”pub from_win32 :: fn(err: u32) -> i32HRESULT_FROM_WIN32; 0 stays 0, negative passes through
ComError
Section titled “ComError”pub ComError :: errors { not_implemented, no_interface, invalid_pointer, aborted, failed, unexpected, out_of_memory, invalid_arg, access_denied, bad_handle, bounds, changed_state, illegal_call, changed_mode, class_not_registered, not_initialized, other,}common failures by name; the rest are .other
not_implemented: E_NOTIMPLno_interface: E_NOINTERFACEinvalid_pointer: E_POINTERaborted: E_ABORTfailed: E_FAILunexpected: E_UNEXPECTEDout_of_memory: E_OUTOFMEMORYinvalid_arg: E_INVALIDARGaccess_denied: E_ACCESSDENIEDbad_handle: E_HANDLEbounds: E_BOUNDSchanged_state: E_CHANGED_STATEillegal_call: E_ILLEGAL_METHOD_CALLchanged_mode: RPC_E_CHANGED_MODE: already initialised the other wayclass_not_registered: REGDB_E_CLASSNOTREGnot_initialized: CO_E_NOTINITIALIZEDother: any other failure
pub check :: fn(hr: i32) -> void ! ComErrorok on any success (S_FALSE too); .other loses the code, keep hr if you need it
IUnknownVtbl
Section titled “IUnknownVtbl”pub IUnknownVtbl :: struct { query_interface: extern fn(*IUnknown, *const Guid, **void) -> i32, add_ref: extern fn(*IUnknown) -> u32, release: extern fn(*IUnknown) -> u32,}IUnknown
Section titled “IUnknown”pub IUnknown :: struct { vtbl: *IUnknownVtbl,}IUnknown.query_interface
Section titled “IUnknown.query_interface”pub query_interface :: fn(self: *Self, iid: *const Guid, out: **void) -> i32on success *out has its own ref to release; null on E_NOINTERFACE
IUnknown.add_ref
Section titled “IUnknown.add_ref”pub add_ref :: fn(self: *Self) -> u32returns the count; diagnostics only, don’t branch on it
IUnknown.release
Section titled “IUnknown.release”pub release :: fn(self: *Self) -> u32last ref destroys the object, pointer is dead after; count is diagnostics only
IInspectableVtbl
Section titled “IInspectableVtbl”pub IInspectableVtbl :: struct { query_interface: extern fn(*IInspectable, *const Guid, **void) -> i32, add_ref: extern fn(*IInspectable) -> u32, release: extern fn(*IInspectable) -> u32, get_iids: extern fn(*IInspectable, *u32, **Guid) -> i32, get_runtime_class_name: extern fn(*IInspectable, *usize) -> i32, get_trust_level: extern fn(*IInspectable, *i32) -> i32,}base of every WinRT interface; read/release its HSTRING with std.winrt
get_iids: ULONG*, IID**: free the array with CoTaskMemFreeget_runtime_class_name: HSTRING*: an owned stringget_trust_level: TrustLevel*
IInspectable
Section titled “IInspectable”pub IInspectable :: struct { vtbl: *IInspectableVtbl,}IInspectable.add_ref
Section titled “IInspectable.add_ref”pub add_ref :: fn(self: *Self) -> u32IInspectable.release
Section titled “IInspectable.release”pub release :: fn(self: *Self) -> u32IInspectable.query_interface
Section titled “IInspectable.query_interface”pub query_interface :: fn(self: *Self, iid: *const Guid, out: **void) -> i32IInspectable.as_unknown
Section titled “IInspectable.as_unknown”pub as_unknown :: fn(self: *Self) -> *IUnknownsame object; first three vtable entries match
IActivationFactoryVtbl
Section titled “IActivationFactoryVtbl”pub IActivationFactoryVtbl :: struct { query_interface: extern fn(*IActivationFactory, *const Guid, **void) -> i32, add_ref: extern fn(*IActivationFactory) -> u32, release: extern fn(*IActivationFactory) -> u32, get_iids: extern fn(*IActivationFactory, *u32, **Guid) -> i32, get_runtime_class_name: extern fn(*IActivationFactory, *usize) -> i32, get_trust_level: extern fn(*IActivationFactory, *i32) -> i32, activate_instance: extern fn(*IActivationFactory, **IInspectable) -> i32,}WinRT class factory, default construction
IActivationFactory
Section titled “IActivationFactory”pub IActivationFactory :: struct { vtbl: *IActivationFactoryVtbl,}IActivationFactory.add_ref
Section titled “IActivationFactory.add_ref”pub add_ref :: fn(self: *Self) -> u32IActivationFactory.release
Section titled “IActivationFactory.release”pub release :: fn(self: *Self) -> u32IActivationFactory.activate_instance
Section titled “IActivationFactory.activate_instance”pub activate_instance :: fn(self: *Self, out: **IInspectable) -> i32default ctor; *out gets an owned IInspectable
BASE_TRUST
Section titled “BASE_TRUST”pub BASE_TRUST :: 0TrustLevel (inspectable.h)
PARTIAL_TRUST
Section titled “PARTIAL_TRUST”pub PARTIAL_TRUST :: 1FULL_TRUST
Section titled “FULL_TRUST”pub FULL_TRUST :: 2RefCount
Section titled “RefCount”pub RefCount :: struct { n: u32,}–– RefCount –– atomic, thread-safe; start at 1, free your object when release() returns 0
RefCount.add
Section titled “RefCount.add”pub add :: fn(self: *Self) -> u32returns the new count
RefCount.release
Section titled “RefCount.release”pub release :: fn(self: *Self) -> u32returns the new count; release at zero is a caller bug, traps in checked builds
RefCount.get
Section titled “RefCount.get”pub get :: fn(self: *Self) -> u32snapshot
new_refcount
Section titled “new_refcount”pub new_refcount :: fn() -> RefCountstarts at 1, the creator’s ref