Skip to main content

Crate windows_core

Crate windows_core 

Expand description

§windows-core

The windows-core crate provides COM and WinRT types, traits, and macros for the windows-* family of crates.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-core]
version = "0.100"

Use the core types as needed:

use windows_core::{h, Result, HRESULT, HSTRING};

// WinRT reference-counted strings.
let name: &HSTRING = h!("Windows.Foundation.Uri");
assert_eq!(name, &HSTRING::from("Windows.Foundation.Uri"));

// HRESULT-based results.
fn check(code: HRESULT) -> Result<()> {
    code.ok()
}

assert!(check(HRESULT(0)).is_ok());
assert!(check(HRESULT(-2147467259)).is_err());

Macros§

h
A literal HSTRING, length-prefixed wide string with a trailing null terminator.
implement_decl
Declares a Rust type as the COM implementer of one or more interfaces, without using the #[implement] proc-macro.
interface_decl
Declares a COM interface inheriting from IUnknown, without using the #[interface] proc-macro.
link
Defines an external function to import.
s
A literal UTF-8 string with a trailing null terminator.
w
A literal UTF-16 wide string with a trailing null terminator.

Structs§

AgileReference
A type representing an agile reference to a COM/WinRT object.
Array
A WinRT array stores elements contiguously in a heap-allocated buffer.
BOOL
A 32-bit Windows Boolean value.
BSTR
A length-prefixed wide string.
ComObject
A counted pointer to a heap-allocated type that implements COM interfaces.
Error
A Windows error code with optional COM error information.
Event
A type that you can use to declare and implement an event of a specified delegate type.
EventRevoker
A handle that automatically revokes an event registration when dropped.
GUID
A globally unique identifier (GUID).
HRESULT
An error code value returned by most COM functions.
HSTRING
An (HSTRING) is a reference-counted and immutable UTF-16 string type.
HStringBuilder
Builder for preallocating immutable HSTRING values.
IInspectable
The base interface for WinRT classes, interfaces, and boxed values.
IUnknown
Base interface for all COM interfaces.
InRef
A borrowed ABI-compatible input parameter.
InterfaceRef
A borrowed COM interface pointer with the same representation as I.
NTSTATUS
An error or status code value returned by some operating system functions.
OutRef
A borrowed ABI-compatible out parameter.
PCSTR
A pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.
PCWSTR
A pointer to a constant null-terminated string of 16-bit Unicode characters.
PSTR
A pointer to a null-terminated string of 8-bit Windows (ANSI) characters.
PWSTR
A pointer to a null-terminated string of 16-bit Unicode characters.
RPC_STATUS
An error or status code value returned by some operating system functions.
StaticComObject
Stores a COM object in static memory.
WIN32_ERROR
An error or status code value returned by some operating system functions.
Weak
Weak holds a non-owning reference to an object.

Traits§

AsImpl
A trait for retrieving the implementation behind a COM or WinRT interface.
ComObjectInner
Identifies types that can be placed in ComObject.
ComObjectInterface
Describes the COM interfaces implemented by a specific COM object.
Interface
Provides low-level access to a COM interface vtable.
OutParam
Converts values to Windows API output parameters.
Param
Converts values to Windows API input parameters.

Functions§

factory
Attempts to load the factory object for the given WinRT class. This can be used to access COM interfaces implemented on a Windows Runtime class factory.
init_mta
Initializes COM for apartment-agnostic code and keeps the multithreaded apartment alive for the rest of the process.

Type Aliases§

Ref
The parameter type for a generic type T used in _Impl trait method signatures.
Result
A specialized Result type that provides Windows error information.

Attribute Macros§

implement
Implements one or more COM interfaces.
interface
Defines a COM interface to call or implement.