winrt topic
Windows Runtime API
The Windows Runtime (WinRT) is a suite of APIs and architectural model,
introduced in Windows 8, that powers the latest generation of Windows APIs. It
is an evolution of the COM API that is designed for access from a variety of
languages. WinRT introduces standardized interfaces for collections (e.g.
IVectorView
), as well as support for generic types and asynchronous
programming models.
Initializing the Windows Runtime
All threads that activate and interact with Windows Runtime objects must be
initialized prior to calling into the Windows Runtime. This package provides the
winrtInitialize
helper function to do this. Call the matching
winrtUninitialize
function to close the Windows Runtime on the current thread.
A successful call to winrtInitialize
should be balanced with a corresponding
call to winrtUninitialize
.
Instantiating Windows Runtime objects
The CreateObject
function provides a convenient way to create a new Windows
Runtime object. This returns a generic Pointer<COMObject>
, which can be cast
to the object type desired. For example:
final comObject = CreateObject('Windows.Globalization.Calendar', IID_ICalendar);
final calendar = ICalendar(comObject);
The object should be disposed of when it is no longer in use, for example:
free(calendar.ptr);
Strings (Windows Runtime)
Windows Runtime APIs use HSTRING
as their native type. An HSTRING is an
immutable string object, which is created with the WindowsCreateString
API
and deleted with the WindowsDeleteString
API. The HSTRING itself is an
integer value, just like other HANDLE
objects in the Win32 programming
interface.
Helper functions exist to easily convert between the Dart String
type and Windows Runtime strings: specifically, convertToHString
and convertFromHString
.
Make sure you dispose of HSTRING
s by calling WindowsDeleteString
; you do
not need to free the pointer itself, since Windows reference counts the
backing store and frees the memory when the reference count reaches 0.
Classes
- ApplicationData winrt
- Calendar winrt Interface
- IApplicationDataStatics winrt Interface
- IAsyncInfo winrt Interface
- ICalendar winrt Interface
- IFileOpenPicker winrt Interface
- IHostName winrt Interface
- INetworkInformationStatics winrt Interface
- IPhoneNumberFormatter winrt Interface
- IPhoneNumberFormatterStatics winrt Interface
- IPropertyValue winrt Interface
- IStorageItem winrt Interface
- IToastNotificationFactory winrt Interface
- IToastNotificationManagerStatics winrt Interface
- IUserDataPathsStatics winrt Interface
-
IVector<
T> winrt Interface -
IVectorView<
T> winrt Interface - PhoneNumberFormatter winrt Interface
- ToastNotification winrt Interface
- UserDataPaths winrt
Mixins
- IApplicationData winrt Interface
- IAsyncAction winrt Interface
Functions
-
convertFromHString(
int hstring) → String winrt -
Takes a
HSTRING
(a WinRT String handle), and converts it to a DartString
. -
convertToHString(
String string) → int winrt -
Takes a Dart String and converts it to an
HSTRING
(a WinRT String), returning an integer handle. -
CreateActivationFactory(
String className, String iid, {Allocator allocator = calloc}) → Pointer< winrtCOMObject> -
Creates the activation factory for the specified runtime class using the
className
andiid
. -
CreateObject(
String className, String iid) → Pointer< winrtCOMObject> - Creates a WinRT object.
-
MetaDataGetDispenser(
Pointer< winrtGUID> rclsid, Pointer<GUID> riid, Pointer<Pointer< ppv) → intNativeType> > - Creates a dispenser class.
-
RoActivateInstance(
int activatableClassId, Pointer< winrtPointer< instance) → intCOMObject> > - Activates the specified Windows Runtime class.
-
RoGetActivationFactory(
int activatableClassId, Pointer< winrtGUID> iid, Pointer<Pointer< factory) → intNativeType> > - Gets the activation factory for the specified runtime class.
-
RoGetApartmentIdentifier(
Pointer< winrtUint64> apartmentIdentifier) → int - Gets a unique identifier for the current apartment.
-
RoGetMetaDataFile(
int name, Pointer< winrtIntPtr> metaDataDispenser, Pointer<IntPtr> metaDataFilePath, Pointer<Pointer< metaDataImport, Pointer<NativeType> >Uint32> typeDefToken) → int - Locates and retrieves the metadata file that describes the Application Binary Interface (ABI) for the specified typename.
-
RoInitialize(
int initType) → int winrt - Initializes the Windows Runtime on the current thread with the specified concurrency model.
-
RoUninitialize(
) → void winrt - Closes the Windows Runtime on the current thread.
-
WindowsCompareStringOrdinal(
int string1, int string2, Pointer< winrtInt32> result) → int - Compares two specified HSTRING objects and returns an integer that indicates their relative position in a sort order.
-
WindowsConcatString(
int string1, int string2, Pointer< winrtIntPtr> newString) → int - Concatenates two specified strings.
-
WindowsCreateString(
Pointer< winrtUtf16> sourceString, int length, Pointer<IntPtr> string) → int - Creates a new HSTRING based on the specified source string.
-
WindowsDeleteString(
int string) → int winrt - Decrements the reference count of a string buffer.
-
WindowsDeleteStringBuffer(
int bufferHandle) → int winrt - Discards a preallocated string buffer if it was not promoted to an HSTRING.
-
WindowsDuplicateString(
int string, Pointer< winrtIntPtr> newString) → int - Creates a copy of the specified string.
-
WindowsGetStringLen(
int string) → int winrt - Gets the length, in Unicode characters, of the specified string.
-
WindowsGetStringRawBuffer(
int string, Pointer< winrtUint32> length) → Pointer<Utf16> - Retrieves the backing buffer for the specified string.
-
WindowsIsStringEmpty(
int string) → int winrt - Indicates whether the specified string is the empty string.
-
WindowsPreallocateStringBuffer(
int length, Pointer< winrtPointer< charBuffer, Pointer<Uint16> >IntPtr> bufferHandle) → int - Allocates a mutable character buffer for use in HSTRING creation.
-
WindowsPromoteStringBuffer(
int bufferHandle, Pointer< winrtIntPtr> string) → int - Creates an HSTRING from the specified HSTRING_BUFFER.
-
WindowsReplaceString(
int string, int stringReplaced, int stringReplaceWith, Pointer< winrtIntPtr> newString) → int - Replaces all occurrences of a set of characters in the specified string with another set of characters to create a new string.
-
WindowsStringHasEmbeddedNull(
int string, Pointer< winrtInt32> hasEmbedNull) → int - Indicates whether the specified string has embedded null characters.
-
WindowsSubstring(
int string, int startIndex, Pointer< winrtIntPtr> newString) → int - Retrieves a substring from the specified string. The substring starts at the specified character position.
-
WindowsSubstringWithSpecifiedLength(
int string, int startIndex, int length, Pointer< winrtIntPtr> newString) → int - Retrieves a substring from the specified string. The substring starts at a specified character position and has a specified length.
-
WindowsTrimStringEnd(
int string, int trimString, Pointer< winrtIntPtr> newString) → int - Removes all trailing occurrences of a specified set of characters from the source string.
-
WindowsTrimStringStart(
int string, int trimString, Pointer< winrtIntPtr> newString) → int - Removes all leading occurrences of a specified set of characters from the source string.
-
winrtInitialize(
) → void winrt - Initializes the Windows Runtime on the current thread with a single-threaded concurrency model.
-
winrtUninitialize(
) → void winrt - Closes the Windows Runtime on the current thread.