Initial commit

This commit is contained in:
Steve Kirbach 2024-02-13 17:59:52 -08:00
commit ba7a8b5000
55 changed files with 9378 additions and 0 deletions

95
.gitignore vendored Normal file
View File

@ -0,0 +1,95 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Obj-C/Swift specific
*.hmap
## App packaging
*.ipa
*.dSYM.zip
*.dSYM
## Playgrounds
timeline.xctimeline
playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm
.build/
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build/
# Accio dependency management
Dependencies/
.accio/
# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
.packages
.generated
swift-winrt.rsp
Package.resolved

11
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Generate swift-windowsfoundation bindings",
"command": "${workspaceFolder:swift-windowsfoundation}/generate-bindings.ps1",
"problemMatcher": []
}
]
}

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
BSD 3-Clause License
Copyright (c) 2024, The Browser Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

21
Package.swift Normal file
View File

@ -0,0 +1,21 @@
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "swift-windowsfoundation",
products: [
.library(name: "WindowsFoundation", type: .dynamic, targets: ["WindowsFoundation"]),
],
dependencies: [
.package(url: "https://github.com/thebrowsercompany/swift-cwinrt", branch: "main"),
],
targets: [
.target(
name: "WindowsFoundation",
dependencies: [
.product(name: "CWinRT", package: "swift-cwinrt"),
]
),
]
)

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# Swift Language Bindings for `Windows.Foundation` APIs
This repository contains the Swift/WinRT language bindings for types in the `Windows.Foundation` namespace. It also contains general helper APIs used throughout all generated bindings.
These APIs are intendened to be used in conjuction with the following projects:
- [swift-uwp](https://github.com/thebrowsercompany/swift-uwp)
- [swift-winui](https://github.com/thebrowsercompany/swift-winui)
- [swift-windowsappsdk](https://github.com/thebrowsercompany/swift-windowsappsdk)
- [swift-win2d](https://github.com/thebrowsercompany/swift-win2d)
## Filing Issues
Please file any issues you have with this repository on https://github.com/thebrowsercompany/swift-winrt
## Known Issues and Limitations
- The developer experience for consuming WinRT APIs from Swift is a work in progress. Due to current limitations, not all APIs can be generated as this causes export limit issues.
- The APIs listed in projections.json are required for the other `swift-*` projects to build. Modify a projections.json in any one of those projects could require an update here.

View File

@ -0,0 +1,128 @@
import CWinRT
import Foundation
// The WinRTClassWeakReference class is a proxy for properly managing the reference count of
// the WinRTClass that is being aggregated. The aggregated object holds a weak reference to
// the outer IInspectable (swift) that is passed in during construction. In general, the
// swift wrappers we create hold strong references to the objects they are wrapping, as we
// expect an AddRef from WinRT to keep the object alive. Since this doesn't happen for aggregated
// objects, we need a proxy which sits in the middle. The WinRTClassWeakReference object doesn't
// keep a strong ref to the swift object, but it forwards all AddRef/Release calls from WinRT
// to the swift object, to ensure it doesn't get cleaned up. The Swift object in turn holds a strong
// reference to this object so that it stays alive.
@_spi(WinRTInternal)
public final class WinRTClassWeakReference<Class: WinRTClass> {
fileprivate weak var instance: Class?
public init(_ instance: Class){
self.instance = instance
}
}
extension WinRTClassWeakReference: CustomQueryInterface {
@_spi(WinRTImplements)
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
guard let instance else { return nil }
return instance.queryInterface(iid)
}
}
extension WinRTClassWeakReference: CustomAddRef {
func addRef() {
guard let instance else { return }
let unmanaged = Unmanaged.passUnretained(instance)
_ = unmanaged.retain()
}
func release() {
guard let instance else { return }
let unmanaged = Unmanaged.passUnretained(instance)
unmanaged.release()
}
}
extension WinRTClassWeakReference: AnyObjectWrapper {
var obj: AnyObject? { instance }
}
@_spi(WinRTInternal)
public protocol ComposableImpl<Class> : AbiInterfaceBridge where SwiftABI: IInspectable, SwiftProjection: WinRTClassWeakReference<Class> {
associatedtype Class: WinRTClass
associatedtype Default : AbiInterface where Default.SwiftABI: WindowsFoundation.IInspectable
static func makeAbi() -> CABI
}
// At a high level, aggregation simply requires the WinRT object to have a pointer back to the Swift world, so that it can call
// overridable methods on the class. This Swift pointer is given to the WinRT object during construction. The construction of the
// WinRT object returns us two different pointers:
// 1. A non-delegating "inner" pointer. A non-delegating pointer means that any QueryInterface calls won't "delegate" back into the Swift world
// 2. A pointer to the default interface.
// Below is a table which shows what the input parameters to CreateInstance is, and what we should do with the
// output parameters in order to properly aggregate a type. For reference, a constructor for a winrt object (without any parameters)
// looks like this:
// CreateInstance(IInspectable* baseInsp, IInspectable** innerInsp, IInspectable** result)
// | Aggregating? | baseInsp (Swift pointer) | innerInsp (C++ pointer) | result (C++) |
// |---------------|---------------------------|-------------------------|--------------------------|
// | Yes | self | stored on swift object | ignored or stored |
// | No | nil | ignored | stored on swift object |
@_spi(WinRTInternal)
public func MakeComposed<Composable: ComposableImpl>(
composing: Composable.Type,
_ this: Composable.Class,
_ createCallback: (UnsealedWinRTClassWrapper<Composable>?, inout WindowsFoundation.IInspectable?) -> Composable.Default.SwiftABI) {
let aggregated = type(of: this) != Composable.Class.self
let wrapper:UnsealedWinRTClassWrapper<Composable>? = .init(aggregated ? this : nil)
var innerInsp: WindowsFoundation.IInspectable? = nil
let base = createCallback(wrapper, &innerInsp)
guard let innerInsp else {
fatalError("Unexpected nil returned after successful creation")
}
if let wrapper {
this.identity = ComPtr(wrapper.toIInspectableABI { $0 })
// Storing a strong ref to the wrapper adds a ref to ourselves, remove the
// reference
wrapper.swiftObj.release()
}
this._inner = aggregated ? innerInsp : base
}
@_spi(WinRTInternal)
public class UnsealedWinRTClassWrapper<Composable: ComposableImpl> : WinRTAbiBridgeWrapper<Composable> {
override public class var IID: WindowsFoundation.IID { Composable.SwiftABI.IID }
public init?(_ impl: Composable.Class?) {
guard let impl = impl else { return nil }
let abi = Composable.makeAbi()
super.init(abi, Composable.SwiftProjection(impl))
}
public static func unwrapFrom(base: ComPtr<Composable.Default.CABI>) -> Composable.Class? {
let overrides: Composable.SwiftABI = try! base.queryInterface()
if let weakRef = tryUnwrapFrom(abi: RawPointer(overrides)) { return weakRef.instance }
guard let instance = makeFrom(abi: overrides) else {
// the derived class doesn't exist, which is fine, just return the type the API specifies.
return make(type: Composable.Class.self, from: overrides)
}
return instance as? Composable.Class
}
public static func tryUnwrapFrom(raw pUnk: UnsafeMutableRawPointer?) -> Composable.Class? {
tryUnwrapFromBase(raw: pUnk)?.instance
}
public func toIInspectableABI<ResultType>(_ body: (UnsafeMutablePointer<C_IInspectable>) throws -> ResultType)
rethrows -> ResultType {
let abi = try! toABI { $0 }
return try abi.withMemoryRebound(to: C_IInspectable.self, capacity: 1) { try body($0) }
}
}
public extension ComposableImpl {
static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
return nil
}
}

View File

@ -0,0 +1,81 @@
// Swift Array to IVector Adaptor
import WinSDK
extension Array {
public func toVector() -> AnyIVector<Element> {
ArrayVector(self)
}
}
internal class ArrayVector<T> : IVector {
typealias Element = T
private var storage: Array<T>
internal init(_ storage: Array<T>){
self.storage = storage
}
// MARK: WinRT APIs
func getAt(_ index: UInt32) -> T { storage[Int(index)] }
var size : UInt32 { UInt32(storage.count) }
func indexOf(_ item: T, _ index: inout UInt32) -> Bool { return false }
func append(_ item: T) { storage.append(item ) }
func setAt(_ index: UInt32, _ item: T) { storage[Int(index)] = item }
func insertAt(_ index: UInt32, _ item: T) { storage.insert(item, at: Int(index)) }
func removeAt(_ index: UInt32) { storage.remove(at: Int(index) )}
func removeAtEnd() { storage.removeLast() }
func clear() { storage.removeAll() }
func getView() -> AnyIVectorView<T>? { return ArrayVectorView(storage) }
func first() -> AnyIIterator<T>? { ArrayIterator(storage) }
}
extension ArrayVector where T: Equatable {
func indexOf(_ item: T, _ index: inout UInt32) throws -> Bool {
guard let foundIndex = storage.firstIndex(of: item) else { return false }
index = UInt32(foundIndex)
return true
}
}
extension ArrayVector {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil }
}
internal class ArrayVectorView<T> : IVectorView {
typealias Element = T
private var storage: Array<T>
internal init(_ storage: Array<T>){
self.storage = storage
}
func getAt(_ index: UInt32) -> T { storage[Int(index)] }
var size : UInt32 { UInt32(storage.count) }
func indexOf(_ item: T, _ index: inout UInt32) -> Bool { return false }
func first() -> AnyIIterator<T>? { ArrayIterator(storage) }
}
extension ArrayVectorView where T: Equatable {
func indexOf(_ item: T, _ index: inout UInt32) throws -> Bool {
guard let foundIndex = storage.firstIndex(of: item) else { return false }
index = UInt32(foundIndex)
return true
}
}
extension ArrayVectorView {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil }
}
class ArrayIterator<T>: IIterator {
typealias Element = T
private let storage: Array<T>
private var index: Int = 0
init(_ storage: Array<T>){
self.storage = storage
}
func moveNext() -> Bool { index += 1; return index < storage.count }
var current: T { storage[index] }
var hasCurrent: Bool { index < storage.count }
func queryInterface(_ iid: IID) -> IUnknownRef? { nil }
}

View File

@ -0,0 +1,36 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
import CWinRT
public func ==<T: Equatable>(_ lhs: (T, T, T, T, T, T, T, T),
_ rhs: (T, T, T, T, T, T, T, T)) -> Bool {
return lhs.0 == rhs.0 &&
lhs.1 == rhs.1 &&
lhs.2 == rhs.2 &&
lhs.3 == rhs.3 &&
lhs.4 == rhs.4 &&
lhs.5 == rhs.5 &&
lhs.6 == rhs.6 &&
lhs.7 == rhs.7
}
extension IInspectable : Equatable {
// Test for COM-style equality.
public static func ==(_ lhs: IInspectable, _ rhs: IInspectable) -> Bool {
let lhsUnknown: IUnknown = try! lhs.QueryInterface()
let rhsUnknown: IUnknown = try! rhs.QueryInterface()
let equals = (lhsUnknown.pUnk.borrow == rhsUnknown.pUnk.borrow)
return equals
}
}
private var IID_IAgileObject: WindowsFoundation.IID {
.init(Data1: 0x94ea2b94, Data2: 0xe9cc, Data3: 0x49e0, Data4: ( 0xc0, 0xff, 0xee, 0x64, 0xca, 0x8f, 0x5b, 0x90 )) // 94ea2b94-e9cc-49e0-c0ff-ee64ca8f5b90
}
public final class IAgileObject : IUnknown {
override public class var IID: WindowsFoundation.IID { IID_IAgileObject }
}

View File

@ -0,0 +1,126 @@
// Copyright © 2023 The Browser Company
// SPDX-License-Identifier: BSD-3
import CWinRT
// ComPtr is a smart pointer for COM interfaces. It holds on to the underlying pointer
// and the semantics of it are meant to mirror that of the ComPtr class in WRL. The
// design of ComPtr and ComPtrs.intialize is that there should be no use of UnsafeMutablePointer
// anywhere else in the code base. The only place where UnsafeMutablePointer should be used is
// where it's required at the ABI boundary.
public class ComPtr<CInterface> {
fileprivate var pUnk: UnsafeMutablePointer<CInterface>?
public init(_ ptr: UnsafeMutablePointer<CInterface>) {
self.pUnk = ptr
asIUnknown {
_ = $0.pointee.lpVtbl.pointee.AddRef($0)
}
}
public convenience init?(_ ptr: UnsafeMutablePointer<CInterface>?) {
guard let ptr else { return nil }
self.init(ptr)
}
fileprivate init?(takingOwnership ptr: UnsafeMutablePointer<CInterface>?) {
guard let ptr else { return nil }
self.pUnk = ptr
}
// Release ownership of the underlying pointer and return it. This is
// useful when assigning to an out parameter and avoids an extra Add/Ref
// release call.
public func detach() -> UnsafeMutableRawPointer? {
let result = pUnk
pUnk = nil
return UnsafeMutableRawPointer(result)
}
public func get() -> UnsafeMutablePointer<CInterface> {
guard let pUnk else { preconditionFailure("get() called on nil pointer") }
return pUnk
}
deinit {
release()
}
private func release() {
guard pUnk != nil else { return }
asIUnknown {
_ = $0.pointee.lpVtbl.pointee.Release($0)
}
}
func asIUnknown<ResultType>(_ body: (UnsafeMutablePointer<C_IUnknown>) throws -> ResultType) rethrows -> ResultType {
guard let pUnk else { preconditionFailure("asIUnknown called on nil pointer") }
return try pUnk.withMemoryRebound(to: C_IUnknown.self, capacity: 1) { try body($0) }
}
}
public extension ComPtr {
func queryInterface<Interface: IUnknown>() throws -> Interface {
let ptr = try self.asIUnknown { pUnk in
var iid = Interface.IID
return try ComPtrs.initialize(to: C_IUnknown.self) { result in
try CHECKED(pUnk.pointee.lpVtbl.pointee.QueryInterface(pUnk, &iid, &result))
}
}
return .init(ptr!)
}
}
// ComPtrs properly initializes pointers who have ownership of the underlying raw pointers. This is used at the ABI boundary layer, for example:
// let (return1, return2) = try ComPtrs.initialize { return1Abi, return2Abi in
// try CHECKED(pThis.pointee.lpVtbl.pointee.Method(pThis, &return1Abi, &return2Abi))
// }
public struct ComPtrs {
// Note: The single initialization methods still return a tuple for ease of code generation
public static func initialize<I>(to: I.Type, _ body: (inout UnsafeMutableRawPointer?) throws -> ()) rethrows -> (ComPtr<I>?) {
var ptrRaw: UnsafeMutableRawPointer?
try body(&ptrRaw)
return (ComPtr(takingOwnership: ptrRaw?.assumingMemoryBound(to: I.self)))
}
public static func initialize<I>(_ body: (inout UnsafeMutablePointer<I>?) throws -> ()) rethrows -> (ComPtr<I>?) {
var ptr: UnsafeMutablePointer<I>?
try body(&ptr)
return (ComPtr(takingOwnership: ptr))
}
public static func initialize<I1, I2>(_ body: (inout UnsafeMutablePointer<I1>?, inout UnsafeMutablePointer<I2>?) throws -> ()) rethrows -> (ComPtr<I1>?, ComPtr<I2>?) {
var ptr1: UnsafeMutablePointer<I1>?
var ptr2: UnsafeMutablePointer<I2>?
try body(&ptr1, &ptr2)
return (ComPtr(takingOwnership: ptr1), ComPtr(takingOwnership: ptr2))
}
public static func initialize<I1, I2, I3>(_ body: (inout UnsafeMutablePointer<I1>?, inout UnsafeMutablePointer<I2>?, inout UnsafeMutablePointer<I3>?) throws -> ()) rethrows -> (ComPtr<I1>?, ComPtr<I2>?, ComPtr<I3>?) {
var ptr1: UnsafeMutablePointer<I1>?
var ptr2: UnsafeMutablePointer<I2>?
var ptr3: UnsafeMutablePointer<I3>?
try body(&ptr1, &ptr2, &ptr3)
return (ComPtr(takingOwnership: ptr1), ComPtr(takingOwnership: ptr2), ComPtr(takingOwnership: ptr3))
}
public static func initialize<I1, I2, I3, I4>(_ body: (inout UnsafeMutablePointer<I1>?, inout UnsafeMutablePointer<I2>?, inout UnsafeMutablePointer<I3>?, inout UnsafeMutablePointer<I4>?) throws -> ()) rethrows -> (ComPtr<I1>?, ComPtr<I2>?, ComPtr<I3>?, ComPtr<I4>?) {
var ptr1: UnsafeMutablePointer<I1>?
var ptr2: UnsafeMutablePointer<I2>?
var ptr3: UnsafeMutablePointer<I3>?
var ptr4: UnsafeMutablePointer<I4>?
try body(&ptr1, &ptr2, &ptr3, &ptr4)
return (ComPtr(takingOwnership: ptr1), ComPtr(takingOwnership: ptr2), ComPtr(takingOwnership: ptr3), ComPtr(takingOwnership: ptr4))
}
public static func initialize<I1, I2, I3, I4, I5>(_ body: (inout UnsafeMutablePointer<I1>?, inout UnsafeMutablePointer<I2>?, inout UnsafeMutablePointer<I3>?, inout UnsafeMutablePointer<I4>?, inout UnsafeMutablePointer<I5>?) throws -> ()) rethrows -> (ComPtr<I1>?, ComPtr<I2>?, ComPtr<I3>?, ComPtr<I4>?, ComPtr<I5>?) {
var ptr1: UnsafeMutablePointer<I1>?
var ptr2: UnsafeMutablePointer<I2>?
var ptr3: UnsafeMutablePointer<I3>?
var ptr4: UnsafeMutablePointer<I4>?
var ptr5: UnsafeMutablePointer<I5>?
try body(&ptr1, &ptr2, &ptr3, &ptr4, &ptr5)
return (ComPtr(takingOwnership: ptr1), ComPtr(takingOwnership: ptr2), ComPtr(takingOwnership: ptr3), ComPtr(takingOwnership: ptr4), ComPtr(takingOwnership: ptr5))
}
}

View File

@ -0,0 +1,35 @@
import CWinRT
#if true // TODO(WIN-860): Remove workaround once C++ interop issues with WinSDK.GUID are fixed.
public typealias GUID = CWinRT.GUID_Workaround
public typealias IID = CWinRT.IID_Workaround
public typealias CLSID = CWinRT.CLSID_Workaround
public typealias REFIID = UnsafePointer<CWinRT.IID_Workaround>
public typealias C_IUnknown = CWinRT.IUnknown_Workaround
public typealias C_IInspectable = CWinRT.IInspectable_Workaround
public typealias C_IInspectableVtbl = CWinRT.IInspectableVtbl_Workaround
public typealias C_IMarshal = CWinRT.IMarshal_Workaround
public typealias C_IMarshalVtbl = CWinRT.IMarshalVtbl_Workaround
internal let CoCreateInstance = CWinRT.CoCreateInstance_Workaround
internal let UuidFromStringA = CWinRT.UuidFromStringA_Workaround
internal let RoActivateInstance = CWinRT.RoActivateInstance_Workaround
internal let RoGetActivationFactory = CWinRT.RoGetActivationFactory_Workaround
internal let StringFromGUID2 = CWinRT.StringFromGUID2_Workaround
internal let CoCreateFreeThreadedMarshaler = CWinRT.CoCreateFreeThreadedMarshaler_Workaround
#else
public typealias GUID = CWinRT.GUID
public typealias IID = CWinRT.IID
public typealias CLSID = CWinRT.CLSID
public typealias REFIID = UnsafePointer<CWinRT.IID>
public typealias C_IUnknown = CWinRT.IUnknown
public typealias C_IInspectable = CWinRT.IInspectable
public typealias C_IInspectableVtbl = CWinRT.IInspectableVtbl
public typealias C_IMarshal = CWinRT.IMarshal
public typealias C_IMarshalVtbl = CWinRT.IMarshalVtbl
internal let CoCreateInstance = CWinRT.CoCreateInstance
internal let UuidFromStringA = CWinRT.UuidFromStringA
internal let RoActivateInstance = CWinRT.RoActivateInstance
internal let RoGetActivationFactory = CWinRT.RoGetActivationFactory
internal let StringFromGUID2 = CWinRT.StringFromGUID2
internal let CoCreateFreeThreadedMarshaler = CWinRT.CoCreateFreeThreadedMarshaler
#endif

View File

@ -0,0 +1,23 @@
import CWinRT
import WinSDK
public protocol CustomQueryInterface {
@_spi(WinRTImplements)
func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef?
}
extension IUnknownRef {
func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
var iid = iid
let (ptr) = try? ComPtrs.initialize(to: C_IUnknown.self) { result in
try CHECKED(borrow.pointee.lpVtbl.pointee.QueryInterface(borrow, &iid, &result))
}
guard let ptr else { return nil}
return IUnknownRef(ptr)
}
}
@_spi(WinRTInternal)
public func queryInterface(_ obj: WinRTClass, _ iid: WindowsFoundation.IID) -> IUnknownRef? {
obj._inner.pUnk.queryInterface(iid)
}

View File

@ -0,0 +1,67 @@
import WinSDK
import Foundation
// Use with debugPrint, dump, etc. to simultaneously output to the debugger and
// console window.
//
// debugPrint("Useful stuff: \(var)", to: &debugOut)
// dump(self, to: &debugOut, name: "myObjectName", indent: 2, maxDepth: 4)
public var debugOut = DebugOutputStream()
public class DebugOutputStream : TextOutputStream {
public func write(_ text: String) {
let sanitizedText = text.replacingOccurrences(of: "", with: "+")
print(sanitizedText, terminator: "")
OutputDebugStringA(sanitizedText)
}
}
public func debugPrintAddress(_ description: String, _ object: AnyObject) {
debugPrint(description, terminator: "", to: &debugOut)
debugPrint(Unmanaged.passUnretained(object).toOpaque(), to: &debugOut)
}
open class TrackableObject {
internal var uniqueId: UInt = 0
public init() {
TrackedObjects.add(self)
}
deinit {
TrackedObjects.remove(self)
}
}
internal class TrackedObject {
private var object: TrackableObject
internal var uniqueId: UInt
private static var idGenerator: UInt = 6000
public init(_ object: TrackableObject) {
self.object = object
self.uniqueId = TrackedObject.idGenerator
object.uniqueId = self.uniqueId
TrackedObject.idGenerator += 1
}
}
public class TrackedObjects {
private static var objects: Array<TrackedObject> = Array()
public static func add(_ object: TrackableObject) {
objects.append(TrackedObject(object))
}
public static func remove(_ object: TrackableObject) {
objects.removeAll(where: { $0.uniqueId == object.uniqueId })
}
public static func dumpAll() {
objects.forEach { object in
print("\r\n------------------------------------------------------------------\r\n")
OutputDebugStringA("\r\n------------------------------------------------------------------\r\n")
dump(object, to: &debugOut, name: String(describing: object), indent: 2, maxDepth: 10)
}
}
}

View File

@ -0,0 +1,58 @@
import WinSDK
// Swift Dictionary to IMap Adaptor
extension Dictionary {
public func toMap() -> AnyIMap<Key, Value> {
DictionaryMap(self)
}
}
internal class DictionaryMap<K, V> : IMap where K : Hashable {
typealias T = AnyIKeyValuePair<Key, Value>?
private var storage: Dictionary<K, V>
internal init(_ storage: Dictionary<K, V>){
self.storage = storage
}
var size : UInt32 { UInt32(storage.count) }
func hasKey(_ K: K) -> Bool { storage[K] != nil }
func lookup(_ K: K) -> V { storage[K]! }
func getView() -> AnyIMapView<K, V>? { DictionaryMapView(storage) }
@discardableResult func insert(_ K: K, _ V: V) -> Bool {
// WinRT returns true if replacing
storage.updateValue(V, forKey: K) != nil
}
func remove(_ K: K) { storage.removeValue(forKey: K) }
func clear() { storage.removeAll(keepingCapacity: true) }
func first() -> AnyIIterator<T>? { fatalError("Not implemented: ArrayVector.First") }
}
extension DictionaryMap {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil }
}
internal class DictionaryMapView<K, V> : IMapView where K : Hashable {
typealias T = AnyIKeyValuePair<Key, Value>?
private var storage: Dictionary<K, V>
internal init(_ storage: Dictionary<K, V>){
self.storage = storage
}
var size : UInt32 { UInt32(storage.count) }
func hasKey(_ key: K) -> Bool { storage[key] != nil }
func lookup(_ key: K) -> V { storage[key]! }
func split(
_ first: inout AnyIMapView<K, V>?,
_ second: inout AnyIMapView<K, V>?) {
fatalError("Not implemented: DictionaryMapView.Split")
}
func first() -> AnyIIterator<T>? { fatalError("Not implemented: ArrayVector.First") }
}
extension DictionaryMapView {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? { nil }
}

View File

@ -0,0 +1,174 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
import CWinRT
// winerror.h
@_transparent
public var E_FAIL: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80004005)
}
@_transparent
public var E_INVALIDARG: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80070057)
}
@_transparent
public var E_NOTIMPL: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80004001)
}
@_transparent
public var E_NOINTERFACE: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80004002)
}
@_transparent
public var E_ACCESSDENIED: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80070005)
}
@_transparent
public var RPC_E_WRONG_THREAD: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8001010E)
}
@_transparent
public var E_BOUNDS: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8000000B)
}
@_transparent
public var CLASS_E_CLASSNOTAVAILABLE: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80040111)
}
@_transparent
public var REGDB_E_CLASSNOTREG: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80040154)
}
@_transparent
public var E_CHANGED_STATE: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8000000C)
}
@_transparent
public var E_ILLEGAL_METHOD_CALL: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8000000E)
}
@_transparent
public var E_ILLEGAL_STATE_CHANGE: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8000000D)
}
@_transparent
public var E_ILLEGAL_DELEGATE_ASSIGNMENT: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80000018)
}
@_transparent
public var ERROR_CANCELLED: WinSDK.HRESULT {
HRESULT(bitPattern: 0x800704C7)
}
@_transparent
public var E_OUTOFMEMORY: WinSDK.HRESULT {
HRESULT(bitPattern: 0x8007000E)
}
@_transparent
public var CO_E_NOTINITIALIZED: WinSDK.HRESULT {
HRESULT(bitPattern: 0x800401F0)
}
@_transparent
public var ERROR_FILE_NOT_FOUND: WinSDK.HRESULT {
HRESULT(bitPattern: 0x80070002)
}
@_transparent
public var E_LAYOUTCYCLE: WinSDK.HRESULT {
HRESULT(bitPattern: 0x802B0014)
}
@_transparent
public var E_XAMLPARSEFAILED : WinSDK.HRESULT {
HRESULT(bitPattern: 0x802B000A)
}
private func getErrorDescription(expecting hr: HRESULT) -> String? {
var errorInfo: UnsafeMutablePointer<IRestrictedErrorInfo>?
guard GetRestrictedErrorInfo(&errorInfo) == S_OK else { return nil }
defer {
_ = errorInfo?.pointee.lpVtbl.pointee.Release(errorInfo)
}
var errorDescription: BSTR?
var restrictedDescription: BSTR?
var capabilitySid: BSTR?
defer {
SysFreeString(errorDescription)
SysFreeString(restrictedDescription)
SysFreeString(capabilitySid)
}
var resultLocal: HRESULT = S_OK
_ = errorInfo?.pointee.lpVtbl.pointee.GetErrorDetails(
errorInfo,
&errorDescription,
&resultLocal,
&restrictedDescription,
&capabilitySid)
guard resultLocal == hr else { return nil }
// Favor restrictedDescription as this is a more user friendly message, which
// is intended to be displayed to the caller to help them understand why the
// api call failed. If it's not set, then fallback to the generic error message
// for the result
if SysStringLen(restrictedDescription) > 0 {
return String(decodingCString: restrictedDescription!, as: UTF16.self)
} else if SysStringLen(errorDescription) > 0 {
return String(decodingCString: errorDescription!, as: UTF16.self)
} else {
return nil
}
}
private func hrToString(_ hr: HRESULT) -> String {
let dwFlags: DWORD = DWORD(FORMAT_MESSAGE_ALLOCATE_BUFFER)
| DWORD(FORMAT_MESSAGE_FROM_SYSTEM)
| DWORD(FORMAT_MESSAGE_IGNORE_INSERTS)
var buffer: UnsafeMutablePointer<WCHAR>? = nil
let dwResult: DWORD = withUnsafeMutablePointer(to: &buffer) {
$0.withMemoryRebound(to: WCHAR.self, capacity: 2) {
FormatMessageW(dwFlags, nil, DWORD(bitPattern: hr),
MAKELANGID(WORD(LANG_NEUTRAL), WORD(SUBLANG_DEFAULT)),
$0, 0, nil)
}
}
guard dwResult > 0, let message = buffer else {
return "HRESULT(0x\(String(DWORD(bitPattern: hr), radix: 16)))"
}
defer { LocalFree(buffer) }
return "0x\(String(DWORD(bitPattern: hr), radix: 16)) - \(String(decodingCString: message, as: UTF16.self))"
}
public struct Error : Swift.Error, CustomStringConvertible {
public let description: String
public let hr: HRESULT
public init(hr: HRESULT) {
self.description = getErrorDescription(expecting: hr) ?? hrToString(hr)
self.hr = hr
}
}
public func failWith(err: HRESULT) -> HRESULT {
return err
}

View File

@ -0,0 +1,15 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
@_alwaysEmitIntoClient @inline(__always)
public func CHECKED(_ body: () -> HRESULT) throws {
let hr: HRESULT = body()
guard hr >= 0 else { throw Error(hr: hr) }
}
@_alwaysEmitIntoClient @inline(__always)
public func CHECKED(_ body: @autoclosure () -> HRESULT) throws {
try CHECKED(body)
}

View File

@ -0,0 +1,44 @@
import WinSDK
import CWinRT
public protocol Disposable {
func dispose()
}
public struct Event<Handler> {
fileprivate var add: (Handler) -> EventRegistrationToken
fileprivate var remove: (_ token: EventRegistrationToken) -> Void
public init(add: @escaping (Handler) -> EventRegistrationToken, remove: @escaping (_ token: EventRegistrationToken) -> Void) {
self.add = add
self.remove = remove
}
@discardableResult public func addHandler(_ handler: Handler) -> EventCleanup {
let token = add(handler)
return EventCleanup(token: token, closeAction: remove)
}
public func removeHandler(_ token: EventRegistrationToken) {
remove(token)
}
}
public struct EventCleanup: Disposable {
fileprivate let token: EventRegistrationToken
let closeAction: (_ token: EventRegistrationToken) -> Void
public init(token: EventRegistrationToken, closeAction: @escaping (_ token: EventRegistrationToken) -> Void) {
self.token = token
self.closeAction = closeAction
}
public func dispose() {
closeAction(token)
}
}
extension CWinRT.EventRegistrationToken {
public static func from(swift: EventCleanup) -> CWinRT.EventRegistrationToken {
return swift.token
}
}

View File

@ -0,0 +1,39 @@
import Foundation
import WinSDK
import CWinRT
struct EventHandlerSubscription<Handler> {
var handler: Handler
var token: CWinRT.EventRegistrationToken
}
struct EventHandlerSubscriptions<Handler> {
typealias Subscription = EventHandlerSubscription<Handler>
private var buffer = [Subscription]()
let lock = NSLock()
init(){}
mutating func append(_ handler: Handler) -> CWinRT.EventRegistrationToken {
let token = CWinRT.EventRegistrationToken(value: Int64(Int(bitPattern: Unmanaged.passUnretained(handler as AnyObject).toOpaque())))
lock.lock()
buffer.append(.init(handler: handler, token: token))
lock.unlock()
return token
}
mutating func remove(token: CWinRT.EventRegistrationToken) {
lock.lock()
// The semantics when the same event handler is added multiple times
// is to append to the end and to remove the last occurrence first.
if let index = buffer.lastIndex(where: { $0.token == token }) {
buffer.remove(at: index)
}
lock.unlock()
}
func getInvocationList() -> [Handler] {
lock.lock()
let result = buffer.map { $0.handler }
lock.unlock()
return result
}
}

View File

@ -0,0 +1,33 @@
import Foundation
import WinSDK
import CWinRT
/// EventSource is the class which implements handling event subscriptions, removals,
/// and invoking events for authoring events in Swift
@propertyWrapper public class EventSource<Handler> {
private var event: Event<Handler>!
private var handlers = EventHandlerSubscriptions<Handler>()
public init() {
event = .init(
add: { self.handlers.append($0) },
remove: { self.handlers.remove(token: $0) }
)
}
public var wrappedValue: Event<Handler> { event }
public func getInvocationList() -> [Handler] {
handlers.getInvocationList()
}
}
extension CWinRT.EventRegistrationToken: @retroactive Hashable {
public static func == (lhs: CWinRT.EventRegistrationToken, rhs: CWinRT.EventRegistrationToken) -> Bool {
return lhs.value == rhs.value
}
public func hash(into hasher: inout Hasher) {
hasher.combine(value)
}
}

View File

@ -0,0 +1,84 @@
import Foundation
import CWinRT
extension GUID: @retroactive CustomStringConvertible {
public var description: String {
withUnsafePointer(to: self) { pGUID in
Array<WCHAR>(unsafeUninitializedCapacity: 40) {
$1 = Int(StringFromGUID2(pGUID, $0.baseAddress, CInt($0.count)))
}.withUnsafeBufferPointer {
String(decodingCString: $0.baseAddress!, as: UTF16.self)
}
}
}
}
extension GUID {
/// Create a GUID from a string such as "E621E1F8-C36C-495A-93FC-0C247A3E6E5F"
///
/// returns nil for invalid strings
public init?(parsingString string: String){
var _self : GUID = .init()
// use UuidFromString because it expects the correct format.
// See https://devblogs.microsoft.com/oldnewthing/20151015-00/?p=91351
var bytes = string.utf8.map { UInt8($0) } + [0]
guard bytes.withUnsafeMutableBufferPointer({ UuidFromStringA($0.baseAddress, &_self) }) == S_OK else { return nil }
self = _self
}
}
extension GUID: @retroactive Equatable {
public static func ==(_ lhs: GUID, _ rhs: GUID) -> Bool {
return lhs.Data1 == rhs.Data1 &&
lhs.Data2 == rhs.Data2 &&
lhs.Data3 == rhs.Data3 &&
lhs.Data4 == rhs.Data4
}
}
public func ~=(_ lhs: GUID, _ rhs: GUID) -> Bool { lhs == rhs}
public extension Foundation.UUID {
init(from guid: GUID) {
let uuid: uuid_t = (
UInt8((guid.Data1 >> 24) & 0xff),
UInt8((guid.Data1 >> 16) & 0xff),
UInt8((guid.Data1 >> 8) & 0xff),
UInt8(guid.Data1 & 0xff),
UInt8((guid.Data2 >> 8) & 0xff),
UInt8(guid.Data2 & 0xff),
UInt8((guid.Data3 >> 8) & 0xff),
UInt8(guid.Data3 & 0xff),
guid.Data4.0,
guid.Data4.1,
guid.Data4.2,
guid.Data4.3,
guid.Data4.4,
guid.Data4.5,
guid.Data4.6,
guid.Data4.7
)
self.init(uuid: uuid)
}
}
public extension GUID {
init(from uuid: Foundation.UUID) {
self.init(
Data1: UInt32((UInt32(uuid.uuid.0) << 24) | (UInt32(uuid.uuid.1) << 16) | (UInt32(uuid.uuid.2) << 8) | UInt32(uuid.uuid.3)),
Data2: UInt16((UInt16(uuid.uuid.4) << 8) | UInt16(uuid.uuid.5)),
Data3: UInt16((UInt16(uuid.uuid.6) << 8) | UInt16(uuid.uuid.7)),
Data4: (
uuid.uuid.8,
uuid.uuid.9,
uuid.uuid.10,
uuid.uuid.11,
uuid.uuid.12,
uuid.uuid.13,
uuid.uuid.14,
uuid.uuid.15
)
)
}
}

View File

@ -0,0 +1,47 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import CWinRT
import Foundation
import ucrt
@_fixed_layout
final public class HString {
internal private(set) var hString: HSTRING?
public init(_ string: String) throws {
self.hString = try string.withCString(encodedAs: UTF16.self) {
var result: HSTRING?
try CHECKED(WindowsCreateString($0, UINT32(wcslen($0)), &result))
return result
}
}
public init(_ hString: HSTRING?) throws {
try CHECKED(WindowsDuplicateString(hString, &self.hString))
}
public init(consuming hString: HSTRING?) {
self.hString = hString
}
public init() { }
public init(_ buffer: UnsafeBufferPointer<WCHAR>?) throws {
try CHECKED(WindowsCreateString(buffer?.baseAddress ?? nil,
UINT32(buffer?.count ?? 0),
&self.hString))
}
public func get() -> HSTRING? { hString }
public func detach() -> HSTRING? {
let tempString = hString
hString = nil
return tempString
}
deinit {
try! CHECKED(WindowsDeleteString(self.hString))
}
}

View File

@ -0,0 +1,64 @@
import CWinRT
import Foundation
/// IBufferByteAccess provides direct access to the underlying bytes of an IBuffer.
/// This buffer is only valid for the lifetime of the IBuffer. For a read-only representation
/// of the buffer, access the bytes through the Data property of the IBuffer.
/// [Open Microsoft Documentation](https://learn.microsoft.com/en-us/windows/win32/api/robuffer/ns-robuffer-ibufferbyteaccess)
public protocol IBufferByteAccess: WinRTInterface {
var buffer: UnsafeMutablePointer<UInt8>? { get throws }
}
public typealias AnyIBufferByteAccess = any IBufferByteAccess
fileprivate let IID_IBufferByteAccess = IID(Data1: 0x905A0FEF, Data2: 0xBC53, Data3: 0x11DF, Data4: ( 0x8C, 0x49, 0x00, 0x1E, 0x4F, 0xC6, 0x86, 0xDA )) // 905a0fef-bc53-11df-8c49-001e4fc686da
extension __ABI_ {
public class IBufferByteAccess: IUnknown {
override public class var IID: IID { IID_IBufferByteAccess}
public func Buffer() throws -> UnsafeMutablePointer<UInt8>? {
var buffer: UnsafeMutablePointer<UInt8>?
try perform(as: CWinRT.C_IBufferByteAccess.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.Buffer(pThis, &buffer))
}
return buffer
}
}
public typealias IBufferByteAccessWrapper = InterfaceWrapperBase<IBufferByteAccessBridge>
}
public enum IBufferByteAccessBridge: AbiInterfaceBridge {
public static func makeAbi() -> CABI {
return CABI(lpVtbl: &IBufferByteAccessVTable)
}
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
// This code path is not actually reachable since IBufferByteAccess is not a WinRT interface.
// It is a COM interface which is implemented by any object which implements the IBuffer interface.
// And the IBufferImpl object will correctly have the implementation of this interface, so this isn't needed
assertionFailure("IBufferByteAccessBridge.from not implemented")
return nil
}
public typealias CABI = CWinRT.C_IBufferByteAccess
public typealias SwiftABI = __ABI_.IBufferByteAccess
public typealias SwiftProjection = AnyIBufferByteAccess
}
private var IBufferByteAccessVTable: CWinRT.C_IBufferByteAccessVtbl = .init(
QueryInterface: { __ABI_.IBufferByteAccessWrapper.queryInterface($0, $1, $2) },
AddRef: { __ABI_.IBufferByteAccessWrapper.addRef($0) },
Release: { __ABI_.IBufferByteAccessWrapper.release($0) },
Buffer: { __ABI_.IBufferByteAccessWrapper.buffer($0, $1) }
)
extension __ABI_.IBufferByteAccessWrapper {
fileprivate static func buffer(_ this: UnsafeMutablePointer<CWinRT.C_IBufferByteAccess>?, _ buffer: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>?) -> HRESULT {
guard let swiftObj = __ABI_.IBufferByteAccessWrapper.tryUnwrapFrom(raw: this) else { return E_INVALIDARG }
guard let buffer else { return E_INVALIDARG }
buffer.pointee = try? swiftObj.buffer
return S_OK
}
}

View File

@ -0,0 +1,79 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import CWinRT
// usually thrown when a call to IInspectable.GetRuntimeClassName
// returns a class name that we cannot resolve. This should
// never be exposed to developers.
struct InvalidRuntimeClassName: Swift.Error {
let className: String
}
extension IInspectable {
public func GetIids() throws -> [WindowsFoundation.IID] {
var iids: UnsafeMutablePointer<WindowsFoundation.IID>?
var iidCount: ULONG = 0
try self.GetIids(&iidCount, &iids)
defer { CoTaskMemFree(iids) }
return Array<WindowsFoundation.IID>(unsafeUninitializedCapacity: Int(iidCount)) {
_ = memcpy($0.baseAddress, iids, MemoryLayout<WindowsFoundation.IID>.stride * Int(iidCount))
$1 = Int(iidCount)
}
}
public func GetRuntimeClassName() throws -> HString {
var className: CWinRT.HSTRING?
try self.GetRuntimeClassName(&className)
return HString(consuming: className)
}
public func GetTrustLevel() throws -> TrustLevel {
var trustLevel: TrustLevel = .BaseTrust
try self.GetTrustLevel(&trustLevel)
return trustLevel
}
}
struct SwiftTypeName {
let module: String
let typeName: String
}
extension IInspectable {
// maps the namespace to a swift module. needs to be kept in sync with
// get_swift_module defined in common.h in the code generator
private func GetSwiftModule(from ns: String) -> String {
if ns.starts(with: "Windows.Foundation") {
return "WindowsFoundation"
} else if ns.starts(with: "Microsoft.UI.Xaml") || ns.starts(with: "Windows.UI.Xaml") {
return "WinUI"
} else if ns.starts(with: "Windows") {
return "UWP"
} else if ns.starts(with: "Microsoft.Web.WebView2.Core") {
return "WebView2Core"
} else if ns.starts(with: "Microsoft.Graphics.Canvas"){
return "Win2D"
} else if ns.starts(with: "Microsoft") {
return "WinAppSDK"
}
var mod: String = ns
mod.removeAll(where: { $0 == "." })
return mod
}
func GetSwiftTypeName() throws -> SwiftTypeName {
let className = try String(hString: GetRuntimeClassName())
let lastNsIndex = className.lastIndex(of: ".")
guard let lastNsIndex = lastNsIndex else {
throw InvalidRuntimeClassName(className: className)
}
let ns = className.prefix(upTo: lastNsIndex)
let lastNsIndexPlus1 = className.index(after: lastNsIndex)
let typeName = className.suffix(from: lastNsIndexPlus1)
return SwiftTypeName(module: GetSwiftModule(from: String(ns)), typeName: String(typeName))
}
}

View File

@ -0,0 +1,141 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import CWinRT
import Foundation
fileprivate let IID_IInspectable = IID(Data1: 0xAF86E2E0, Data2: 0xB12D, Data3: 0x4C6A, Data4: ( 0x9C, 0x5A, 0xD7, 0xAA, 0x65, 0x10, 0x1E, 0x90 )) // AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90
open class IInspectable: IUnknown {
override open class var IID: WindowsFoundation.IID { IID_IInspectable }
public func GetIids(_ iidCount: UnsafeMutablePointer<ULONG>, _ iids: UnsafeMutablePointer<UnsafeMutablePointer<WindowsFoundation.IID>?>?) throws {
return try perform(as: C_IInspectable.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.GetIids(pThis, iidCount, iids))
}
}
public func GetRuntimeClassName(_ className: UnsafeMutablePointer<HSTRING?>) throws {
return try perform(as: C_IInspectable.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.GetRuntimeClassName(pThis, className))
}
}
public func GetTrustLevel(_ trustLevel: UnsafeMutablePointer<TrustLevel>?) throws {
return try perform(as: C_IInspectable.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.GetTrustLevel(pThis, trustLevel))
}
}
}
// Provide facilities for creating a general IInspectable vtbl which can hold onto any UnsealedWinRTClass.
// These types are used for composable types which don't provide an overrides interface. Composable types which
// follow this pattern should define their composability contract like the following:
// internal class IBaseNoOverrides : OverridesImpl {
// internal typealias CABI = C_IInspectable
// internal typealias SwiftABI = __ABI_WindowsFoundation.IBaseNoOverrides
// internal typealias SwiftProjection = BaseNoOverrides
// internal typealias c_defaultABI = __x_ABI_Ctest__component_CIBaseNoOverrides
// internal typealias swift_overrides = WindowsFoundation.IInspectable
// }
// internal typealias Composable = IBaseNoOverrides
protocol AnyObjectWrapper {
var obj: AnyObject? { get }
}
public enum __ABI_ {
public class AnyWrapper : WinRTWrapperBase<C_IInspectable, AnyObject> {
public init?(_ swift: Any?) {
guard let swift else { return nil }
if let propertyValue = PropertyValue.createFrom(swift) {
let abi: UnsafeMutablePointer<C_IInspectable> = RawPointer(propertyValue)
super.init(abi.pointee, propertyValue)
} else {
let vtblPtr = withUnsafeMutablePointer(to: &IInspectableVTable) { $0 }
let cAbi = C_IInspectable(lpVtbl: vtblPtr)
super.init(cAbi, swift as AnyObject)
}
}
override public func toABI<ResultType>(_ body: (UnsafeMutablePointer<C_IInspectable>) throws -> ResultType)
throws -> ResultType {
if let swiftAbi = swiftObj as? IInspectable {
let abi: UnsafeMutablePointer<C_IInspectable> = RawPointer(swiftAbi)
return try body(abi)
} else {
return try super.toABI(body)
}
}
public static func unwrapFrom(abi: ComPtr<C_IInspectable>?) -> Any? {
guard let abi = abi else { return nil }
if let instance = tryUnwrapFrom(abi: abi) {
if let weakRef = instance as? AnyObjectWrapper { return weakRef.obj }
return instance
}
let ref = IInspectable(abi)
return makeFrom(abi: ref) ?? ref
}
public static func tryUnwrapFrom(raw pUnk: UnsafeMutableRawPointer?) -> AnyObject? {
tryUnwrapFromBase(raw: pUnk)
}
}
internal static var IInspectableVTable: C_IInspectableVtbl = .init(
QueryInterface: {
guard let pUnk = $0, let riid = $1, let ppvObject = $2 else { return E_INVALIDARG }
ppvObject.pointee = nil
if riid.pointee == IUnknown.IID ||
riid.pointee == IInspectable.IID ||
riid.pointee == ISwiftImplemented.IID ||
riid.pointee == IAgileObject.IID {
_ = pUnk.pointee.lpVtbl.pointee.AddRef(pUnk)
ppvObject.pointee = UnsafeMutableRawPointer(pUnk)
return S_OK
}
let swiftObj = AnyWrapper.tryUnwrapFrom(raw: pUnk)
if let customQueryInterface = swiftObj as? CustomQueryInterface,
let result = customQueryInterface.queryInterface(riid.pointee) {
ppvObject.pointee = result.detach()
return S_OK
}
return E_NOINTERFACE
},
AddRef: { AnyWrapper.addRef($0) },
Release: { AnyWrapper.release($0) },
GetIids: {
let size = MemoryLayout<WindowsFoundation.IID>.size
let iids = CoTaskMemAlloc(UInt64(size) * 2).assumingMemoryBound(to: WindowsFoundation.IID.self)
iids[0] = IUnknown.IID
iids[1] = IInspectable.IID
$1!.pointee = 2
$2!.pointee = iids
return S_OK
},
GetRuntimeClassName: {
guard let instance = AnyWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
guard let winrtClass = instance as? WinRTClass else {
let string = String(reflecting: type(of: instance))
$1!.pointee = try! HString(string).detach()
return S_OK
}
$1!.pointee = winrtClass.GetRuntimeClassName().detach()
return S_OK
},
GetTrustLevel: {
_ = $0
$1!.pointee = TrustLevel(rawValue: 0)
return S_OK
}
)
}
extension ComposableImpl where CABI == C_IInspectable {
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_.IInspectableVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}

View File

@ -0,0 +1,58 @@
// Swift Dictionary-like extensions to IMap[View]
extension IMap {
public typealias Key = K
public typealias Value = V
public var count: Int { Int(size) }
public var underestimatedCount: Int { Int(size) }
public var isEmpty: Bool { size == 0 }
public subscript(key: Key) -> Value? {
get { hasKey(key) ? lookup(key) : nil }
set(newValue) {
if let value = newValue {
_ = insert(key, value)
}
else {
remove(key)
}
}
}
public subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value {
get { hasKey(key) ? lookup(key) : defaultValue() }
}
@discardableResult
public func updateValue(_ value: Value, forKey key: Key) -> Value? {
let oldValue = hasKey(key) ? lookup(key) : nil
_ = insert(key, value)
return oldValue
}
@discardableResult
public func removeValue(forKey key: Key) -> Value? {
let oldValue = hasKey(key) ? lookup(key) : nil
remove(key)
return oldValue
}
public func removeAll() { clear() }
}
extension IMapView {
public typealias Key = K
public typealias Value = V
public var count: Int { Int(size) }
public var underestimatedCount: Int { Int(size) }
public var isEmpty: Bool { size == 0 }
public subscript(key: Key) -> Value? {
hasKey(key) ? lookup(key) : nil
}
public subscript(key: Key, default defaultValue: @autoclosure () -> Value) -> Value {
get { hasKey(key) ? lookup(key) : defaultValue() }
}
}

View File

@ -0,0 +1,74 @@
import CWinRT
import Foundation
/// IMemoryBufferByteAccess provides direct access to the underlying bytes of an IMemoryBuffer.
/// This buffer is only valid for the lifetime of the buffer. For a read-only representation
/// of the buffer, access the bytes through the Data property of the IBuffer.
/// [Open Microsoft Documentation](https://learn.microsoft.com/en-us/previous-versions/mt297505(v=vs.85))
public protocol IMemoryBufferByteAccess: WinRTInterface {
var buffer: UnsafeMutableBufferPointer<UInt8>? { get throws }
}
public typealias AnyIMemoryBufferByteAccess = any IMemoryBufferByteAccess
fileprivate let IID_IMemoryBufferByteAccess = IID(Data1: 0x5B0D3235, Data2: 0x4DBA, Data3: 0x4D44, Data4: ( 0x86, 0x5E, 0x8F, 0x1D, 0x0E, 0x4F, 0xD0, 0x4D )) // 5b0d3235-4dba-4d44-865e-8f1d0e4fd04d
extension __ABI_ {
public class IMemoryBufferByteAccess: IUnknown {
override public class var IID: IID { IID_IMemoryBufferByteAccess}
public func Buffer() throws -> UnsafeMutableBufferPointer<UInt8>? {
var capacity: UInt32 = 0
let ptr = try GetBuffer(&capacity)
return UnsafeMutableBufferPointer(start: ptr, count: Int(capacity))
}
fileprivate func GetBuffer(_ capacity: inout UInt32) throws -> UnsafeMutablePointer<UInt8>? {
var buffer: UnsafeMutablePointer<UInt8>?
try perform(as: CWinRT.IMemoryBufferByteAccess.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.GetBuffer(pThis, &buffer, &capacity))
}
return buffer
}
}
public typealias IMemoryBufferByteAccessWrapper = InterfaceWrapperBase<IMemoryBufferByteAccessBridge>
}
public enum IMemoryBufferByteAccessBridge: AbiInterfaceBridge {
public static func makeAbi() -> CABI {
return CABI(lpVtbl: &IMemoryBufferByteAccessVTable)
}
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
// This code path is not actually reachable since IMemoryBufferByteAccess is not a WinRT interface.
// It is a COM interface which is implemented by any object which implements the IMemoryBufferReference interface.
// And the IMemoryBufferReferenceImpl object will correctly have the implementation of this interface, so this isn't needed
assertionFailure("IMemoryBufferByteAccessBridge.from not implemented")
return nil
}
public typealias CABI = CWinRT.IMemoryBufferByteAccess
public typealias SwiftABI = __ABI_.IMemoryBufferByteAccess
public typealias SwiftProjection = AnyIMemoryBufferByteAccess
}
fileprivate var IMemoryBufferByteAccessVTable: CWinRT.IMemoryBufferByteAccessVtbl = .init(
QueryInterface: { __ABI_.IMemoryBufferByteAccessWrapper.queryInterface($0, $1, $2) },
AddRef: { __ABI_.IMemoryBufferByteAccessWrapper.addRef($0) },
Release: { __ABI_.IMemoryBufferByteAccessWrapper.release($0) },
GetBuffer: { __ABI_.IMemoryBufferByteAccessWrapper.getBuffer($0, $1, $2) }
)
extension __ABI_.IMemoryBufferByteAccessWrapper {
fileprivate static func getBuffer(_ this: UnsafeMutablePointer<CWinRT.IMemoryBufferByteAccess>?, _ buffer: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>?, _ count: UnsafeMutablePointer<UInt32>?) -> HRESULT {
guard let swiftObj = __ABI_.IMemoryBufferByteAccessWrapper.tryUnwrapFrom(raw: this) else { return E_INVALIDARG }
guard let buffer, let count else { return E_INVALIDARG }
count.pointee = 0
buffer.pointee = nil
guard let swiftBuffer = try? swiftObj.buffer else { return E_FAIL }
count.pointee = UInt32(swiftBuffer.count)
buffer.pointee = swiftBuffer.baseAddress
return S_OK
}
}

View File

@ -0,0 +1,41 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
extension IUnknown {
public func QueryInterface<Interface: IUnknown>() throws -> Interface {
var iid = Interface.IID
let (pointer) = try ComPtrs.initialize(to: C_IUnknown.self) { abi in
try CHECKED(self.pUnk.borrow.pointee.lpVtbl.pointee.QueryInterface(self.pUnk.borrow, &iid, &abi))
}
return Interface(pointer!)
}
}
extension IUnknown {
@_alwaysEmitIntoClient @inline(__always)
public func perform<Type, ResultType>(as type: Type.Type,
_ body: (UnsafeMutablePointer<Type>) throws -> ResultType)
throws -> ResultType {
let pThis = UnsafeMutableRawPointer(self.pUnk.borrow).bindMemory(to: Type.self, capacity: 1)
return try body(pThis)
}
}
extension IUnknown {
public static func CreateInstance<Interface: IUnknown>(`class` clsid: CLSID,
outer pUnkOuter: IUnknown? = nil,
context dwClsContext: CLSCTX = CLSCTX_INPROC_SERVER)
throws -> Interface {
var clsid = clsid
var iid = Interface.IID
let (instance) = try ComPtrs.initialize(to: C_IUnknown.self) { instanceAbi in
try CHECKED(CoCreateInstance(&clsid, RawPointer(pUnkOuter), DWORD(dwClsContext.rawValue), &iid, &instanceAbi))
}
// https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cocreateinstance
// "Upon successful return, *ppv contains the requested interface pointer."
return try instance!.queryInterface()
}
}

View File

@ -0,0 +1,35 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
import CWinRT
fileprivate let IID_IUnknown = IID(Data1: 0x00000000, Data2: 0x0000, Data3: 0x0000, Data4: ( 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 )) // 00000000-0000-0000-C000-000000000046
open class IUnknown : HasIID {
public let pUnk: IUnknownRef
open class var IID: WindowsFoundation.IID { IID_IUnknown }
public required init<CInterface>(_ pointer: ComPtr<CInterface>) {
self.pUnk = .init(pointer)
}
@_alwaysEmitIntoClient @inline(__always)
public func QueryInterface(_ iid: REFIID, _ ppvObject: UnsafeMutablePointer<UnsafeMutableRawPointer?>?) throws {
let pUnk: UnsafeMutablePointer<C_IUnknown>! = self.pUnk.borrow
try CHECKED(pUnk.pointee.lpVtbl.pointee.QueryInterface(pUnk, iid, ppvObject))
}
@_alwaysEmitIntoClient @inline(__always) @discardableResult
public func AddRef() -> ULONG {
let pUnk: UnsafeMutablePointer<C_IUnknown>! = self.pUnk.borrow
return pUnk.pointee.lpVtbl.pointee.AddRef(pUnk)
}
@_alwaysEmitIntoClient @inline(__always) @discardableResult
public func Release() -> ULONG {
let pUnk: UnsafeMutablePointer<C_IUnknown>! = self.pUnk.borrow
return pUnk.pointee.lpVtbl.pointee.Release(pUnk)
}
}

View File

@ -0,0 +1,21 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
@_fixed_layout
public final class IUnknownRef {
private var pUnk: ComPtr<C_IUnknown>
init<C_Interface>(_ pUnk: ComPtr<C_Interface>) {
let pointer: UnsafeMutablePointer<C_IUnknown> =
UnsafeMutableRawPointer(pUnk.get()).bindMemory(to: C_IUnknown.self, capacity: 1)
self.pUnk = .init(pointer)
}
func detach() -> UnsafeMutableRawPointer? {
return self.pUnk.detach()
}
public var borrow: UnsafeMutablePointer<C_IUnknown> {
return self.pUnk.get()
}
}

View File

@ -0,0 +1,43 @@
// Default Swift Collection protocol implementation for IVector
public extension IVector {
var startIndex: Int { 0 }
var endIndex: Int { count }
var count: Int { Int(size) }
subscript(position: Int) -> Element {
get { getAt(UInt32(position)) }
set(newValue) { setAt(UInt32(position), newValue) }
}
func index(after i: Int) -> Int { i+1 }
func removeLast() { removeAtEnd()}
func index(of: Element) -> Int? {
var index: UInt32 = 0
let result = indexOf(of, &index)
guard result else { return nil }
return Int(index)
}
func remove(at: Int) -> Element {
let item = self[at]
removeAt(UInt32(at))
return item
}
}
public extension IVectorView {
var startIndex: Int { 0 }
var endIndex: Int { count }
var count: Int { Int(size) }
func index(after i: Int) -> Int { i+1}
subscript(position: Int) -> Element { getAt(UInt32(position)) }
func index(of: Element) -> Int? {
var index: UInt32 = 0
let result = indexOf(of, &index)
guard result else { return nil }
return Int(index)
}
}

View File

@ -0,0 +1,31 @@
import Foundation
// Not strongly typed, we lose the type safety of the associatedtype anyways
// when we cast to `any MakeFromAbi`, plus that requires a lot more exported
// simples than we want
public protocol MakeFromAbi {
static func from(typeName: String, abi: WindowsFoundation.IInspectable) -> Any?
}
func make(typeName: SwiftTypeName, from abi: WindowsFoundation.IInspectable) -> Any? {
guard let makerType = NSClassFromString("\(typeName.module).__MakeFromAbi") as? any MakeFromAbi.Type else {
return nil
}
return makerType.from(typeName: typeName.typeName, abi: abi)
}
func makeFrom(abi: WindowsFoundation.IInspectable) -> Any? {
// When creating a swift class which represents this type, we want to get the class name that we're trying to create
// via GetRuntimeClassName so that we can create the proper derived type. For example, the API may return UIElement,
// but we want to return a Button type.
// Note that we'll *never* be trying to create an app implemented object at this point
guard let className = try? abi.GetSwiftTypeName() else { return nil }
return make(typeName: className, from: abi)
}
func make<T:AnyObject>(type: T.Type, from abi: WindowsFoundation.IInspectable) -> T? {
let classString = NSStringFromClass(type).split(separator: ".", maxSplits: 2)
return make(typeName: SwiftTypeName(module: String(classString[0]), typeName: String(classString[1])), from: abi) as? T
}

View File

@ -0,0 +1,136 @@
import CWinRT
internal let IID_IMarshal: IID = IID(Data1: 0x01000300, Data2: 0x0000, Data3: 0x0000, Data4: (0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)) // 01000300-0000-0000-C000-00000046
fileprivate extension IUnknownRef {
func copyTo(_ riid: REFIID?, _ ppvObj: UnsafeMutablePointer<LPVOID?>?) -> HRESULT {
self.borrow.pointee.lpVtbl.pointee.QueryInterface(self.borrow, riid, ppvObj)
}
}
func makeMarshaler(_ outer: IUnknownRef, _ result: UnsafeMutablePointer<UnsafeMutableRawPointer?>) throws {
let marshaler = try Marshaler(outer)
let wrapper = MarshalWrapper(marshaler)
try wrapper.toABI {
_ = $0.pointee.lpVtbl.pointee.AddRef($0)
result.pointee = UnsafeMutableRawPointer($0)
}
}
fileprivate class MarshalWrapper: WinRTAbiBridgeWrapper<IMarshalBridge> {
init(_ marshaler: Marshaler){
super.init(IMarshalBridge.makeAbi(), marshaler)
}
}
fileprivate enum IMarshalBridge: AbiBridge {
static func makeAbi() -> C_IMarshal {
return C_IMarshal(lpVtbl: &IMarshalVTable)
}
static func from(abi: ComPtr<C_IMarshal>?) -> Marshaler? {
guard let abi = abi else { return nil }
return try? Marshaler(IUnknownRef(abi))
}
typealias CABI = C_IMarshal
typealias SwiftProjection = Marshaler
}
private var IMarshalVTable: C_IMarshalVtbl = .init(
QueryInterface: { pUnk, riid, ppvObject in
guard let pUnk, let riid, let ppvObject else { return E_INVALIDARG }
switch riid.pointee {
case IID_IMarshal:
_ = pUnk.pointee.lpVtbl.pointee.AddRef(pUnk)
return S_OK
default:
guard let obj = MarshalWrapper.tryUnwrapFromBase(raw: pUnk)?.obj else { return E_NOINTERFACE }
return obj.copyTo(riid, ppvObject)
}
},
AddRef: { MarshalWrapper.addRef($0) },
Release: { MarshalWrapper.release($0) },
GetUnmarshalClass: { Marshaler.GetUnmarshalClass($0, $1, $2, $3, $4, $5, $6) },
GetMarshalSizeMax: { Marshaler.GetMarshalSizeMax($0, $1, $2, $3, $4, $5, $6) },
MarshalInterface: { Marshaler.MarshalInterface($0, $1, $2, $3, $4, $5, $6) },
UnmarshalInterface: { Marshaler.UnmarshalInterface($0, $1, $2, $3)},
ReleaseMarshalData: { Marshaler.ReleaseMarshalData($0, $1) },
DisconnectObject: { Marshaler.DisconnectObject($0, $1) }
)
private class Marshaler {
var obj: IUnknownRef
init(_ obj: IUnknownRef) throws {
self.obj = obj
var marshalerPtr: UnsafeMutablePointer<C_IUnknown>?
try CHECKED(CoCreateFreeThreadedMarshaler(nil, &marshalerPtr))
guard let marshalerPtr else { throw WindowsFoundation.Error(hr: E_FAIL) }
marshaler = UnsafeMutableRawPointer(marshalerPtr).bindMemory(to: C_IMarshal.self, capacity: 1)
}
deinit {
_ = marshaler.pointee.lpVtbl.pointee.Release(marshaler)
}
var marshaler: UnsafeMutablePointer<C_IMarshal>
static func GetUnmarshalClass(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ riid: REFIID?,
_ pv: UnsafeMutableRawPointer?,
_ dwDestContext: DWORD,
_ pvDestContext: UnsafeMutableRawPointer?,
_ mshlflags: DWORD,
_ pCid: UnsafeMutablePointer<CLSID>?) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.GetUnmarshalClass(marshaler, riid, pv, dwDestContext, pvDestContext, mshlflags, pCid)
}
static func GetMarshalSizeMax(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ riid: REFIID?, _ pv: UnsafeMutableRawPointer?,
_ dwDestContext: DWORD,
_ pvDestContext: UnsafeMutableRawPointer?,
_ mshlflags: DWORD,
_ pSize: UnsafeMutablePointer<DWORD>?) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.GetMarshalSizeMax(marshaler, riid, pv, dwDestContext, pvDestContext, mshlflags, pSize)
}
static func MarshalInterface(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ pStm: UnsafeMutablePointer<IStream>?,
_ riid: REFIID?,
_ pv: UnsafeMutableRawPointer?,
_ dwDestContext: DWORD,
_ pvDestContext: UnsafeMutableRawPointer?,
_ mshlflags: DWORD) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.MarshalInterface(marshaler, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags)
}
static func UnmarshalInterface(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ pStm: UnsafeMutablePointer<IStream>?,
_ riid: REFIID?,
_ ppv: UnsafeMutablePointer<UnsafeMutableRawPointer?>?) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.UnmarshalInterface(marshaler, pStm, riid, ppv)
}
static func ReleaseMarshalData(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ pStm: UnsafeMutablePointer<IStream>?) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.ReleaseMarshalData(marshaler, pStm)
}
static func DisconnectObject(
_ this: UnsafeMutablePointer<C_IMarshal>?,
_ dwReserved: DWORD) -> HRESULT {
guard let marshaler = MarshalWrapper.tryUnwrapFrom(abi: ComPtr(this))?.marshaler else { return E_FAIL }
return marshaler.pointee.lpVtbl.pointee.DisconnectObject(marshaler, dwReserved)
}
}

View File

@ -0,0 +1,173 @@
import CWinRT
import WinSDK
// Internal implementation of IPropertyValue
fileprivate var IID___x_ABI_CWindows_CFoundation_CIPropertyValueStatics: WindowsFoundation.IID {
.init(Data1: 0x629BDBC8, Data2: 0xD932, Data3: 0x4FF4, Data4: ( 0x96,0xB9,0x8D,0x96,0xC5,0xC1,0xE8,0x58 ))// 629BDBC8-D932-4FF4-96B9-8D96C5C1E858
}
internal class IPropertyValueStatics: WindowsFoundation.IInspectable {
override public class var IID: WindowsFoundation.IID { IID___x_ABI_CWindows_CFoundation_CIPropertyValueStatics }
internal func CreateUInt8Impl(_ value: UINT8) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateUInt8(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateInt16Impl(_ value: INT16) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateInt16(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateUInt16Impl(_ value: UINT16) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateUInt16(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateInt32Impl(_ value: INT32) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateInt32(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateUInt32Impl(_ value: UINT32) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateUInt32(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateInt64Impl(_ value: INT64) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateInt64(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateUInt64Impl(_ value: UINT64) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateUInt64(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateSingleImpl(_ value: FLOAT) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateSingle(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateDoubleImpl(_ value: DOUBLE) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateDouble(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateChar16Impl(_ value: WCHAR) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateChar16(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateBooleanImpl(_ value: boolean) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateBoolean(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateStringImpl(_ value: HSTRING?) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateString(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateGuidImpl(_ value: GUID) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateGuid(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateDateTimeImpl(_ value: __x_ABI_CWindows_CFoundation_CDateTime) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateDateTime(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateTimeSpanImpl(_ value: __x_ABI_CWindows_CFoundation_CTimeSpan) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateTimeSpan(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreatePointImpl(_ value: __x_ABI_CWindows_CFoundation_CPoint) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreatePoint(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateSizeImpl(_ value: __x_ABI_CWindows_CFoundation_CSize) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateSize(pThis, value, &abi))
}
}
return propertyValue
}
internal func CreateRectImpl(_ value: __x_ABI_CWindows_CFoundation_CRect) throws -> ComPtr<C_IInspectable>? {
let (propertyValue) = try ComPtrs.initialize { abi in
_ = try perform(as: __x_ABI_CWindows_CFoundation_CIPropertyValueStatics.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.CreateRect(pThis, value, &abi))
}
}
return propertyValue
}
}

View File

@ -0,0 +1,142 @@
import Foundation
import CWinRT
import WinSDK
// Handwritten implementation for PropertyValue which *doesn't* try to do the IInspectable <-> Any mapping.
// This class is used by the AnyWrapper to create IInspectable instances from this subset of known Any values.
internal final class PropertyValue {
private static let _IPropertyValueStatics: IPropertyValueStatics = try! RoGetActivationFactory(HString("Windows.Foundation.PropertyValue"))
public static func createUInt8(_ value: UInt8) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateUInt8Impl(value)
return .init(propertyValue!)
}
public static func createInt16(_ value: Int16) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateInt16Impl(value)
return .init(propertyValue!)
}
public static func createUInt16(_ value: UInt16) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateUInt16Impl(value)
return .init(propertyValue!)
}
public static func createInt32(_ value: Int32) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateInt32Impl(value)
return .init(propertyValue!)
}
public static func createUInt32(_ value: UInt32) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateUInt32Impl(value)
return .init(propertyValue!)
}
public static func createInt64(_ value: Int64) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateInt64Impl(value)
return .init(propertyValue!)
}
public static func createUInt64(_ value: UInt64) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateUInt64Impl(value)
return .init(propertyValue!)
}
public static func createSingle(_ value: Float) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateSingleImpl(value)
return .init(propertyValue!)
}
public static func createDouble(_ value: Double) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateDoubleImpl(value)
return .init(propertyValue!)
}
public static func createBoolean(_ value: Bool) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateBooleanImpl(.init(from: value))
return .init(propertyValue!)
}
public static func createString(_ value: String) -> WindowsFoundation.IInspectable {
let _value = try! HString(value)
let propertyValue = try! _IPropertyValueStatics.CreateStringImpl(_value.get())
return .init(propertyValue!)
}
public static func createGuid(_ value: GUID) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateGuidImpl(value)
return .init(propertyValue!)
}
public static func createDateTime(_ value: DateTime) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateDateTimeImpl(.from(swift: value))
return .init(propertyValue!)
}
public static func createTimeSpan(_ value: TimeSpan) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateTimeSpanImpl(.from(swift: value))
return .init(propertyValue!)
}
public static func createPoint(_ value: Point) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreatePointImpl(.from(swift: value))
return .init(propertyValue!)
}
public static func createSize(_ value: Size) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateSizeImpl(.from(swift: value))
return .init(propertyValue!)
}
public static func createRect(_ value: Rect) -> WindowsFoundation.IInspectable {
let propertyValue = try! _IPropertyValueStatics.CreateRectImpl(.from(swift: value))
return .init(propertyValue!)
}
}
extension PropertyValue
{
static func createInt(_ value: Int) -> WindowsFoundation.IInspectable {
#if arch(x86_64) || arch(arm64)
return PropertyValue.createInt64(Int64(value))
#elseif arch(i386) || arch(arm)
return PropertyValue.createInt32(Int32(value))
#else
fatalError("unknown process architecture size")
#endif
}
static func createUInt(_ value: UInt) -> WindowsFoundation.IInspectable {
#if arch(x86_64) || arch(arm64)
return PropertyValue.createUInt64(UInt64(value))
#elseif arch(i386) || arch(arm)
return PropertyValue.createUInt32(UInt32(value))
#else
fatalError("unknown process architecture size")
#endif
}
static func createFrom(_ any: Any) -> WindowsFoundation.IInspectable? {
switch any {
case let value as String: return PropertyValue.createString(value)
case let value as Int: return PropertyValue.createInt(value)
case let value as Int16: return PropertyValue.createInt16(value)
case let value as Int32: return PropertyValue.createInt32(value)
case let value as Int64: return PropertyValue.createInt64(value)
case let value as UInt: return PropertyValue.createUInt(value)
case let value as UInt8: return PropertyValue.createUInt8(value)
case let value as UInt32: return PropertyValue.createUInt32(value)
case let value as UInt64: return PropertyValue.createUInt64(value)
case let value as Float: return PropertyValue.createSingle(value)
case let value as Double: return PropertyValue.createDouble(value)
case let value as Bool: return PropertyValue.createBoolean(value)
case let value as GUID: return PropertyValue.createGuid(value)
case let value as DateTime: return PropertyValue.createDateTime(value)
case let value as TimeSpan: return PropertyValue.createTimeSpan(value)
case let value as Point: return PropertyValue.createPoint(value)
case let value as Size: return PropertyValue.createSize(value)
case let value as Rect: return PropertyValue.createRect(value)
default: return nil
}
}
}

View File

@ -0,0 +1,32 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
public func RawPointer<T: IUnknown, U>(_ pUnk: T) -> UnsafeMutablePointer<U> {
return UnsafeMutableRawPointer(pUnk.pUnk.borrow).bindMemory(to: U.self, capacity: 1)
}
public func RawPointer<T: IUnknown, U>(_ pUnk: T) -> ComPtr<U> {
return ComPtr(UnsafeMutableRawPointer(pUnk.pUnk.borrow).bindMemory(to: U.self, capacity: 1))
}
public func RawPointer<T: IUnknown, U>(_ pUnk: T?) -> UnsafeMutablePointer<U>? {
guard let pUnk else { return nil }
let result: UnsafeMutablePointer<U> = RawPointer(pUnk)
return result
}
public func RawPointer<T: WinRTClass, U>(_ obj: T?) -> UnsafeMutablePointer<U>? {
return obj?._getABI()
}
public func RawPointer<T: AbiInterfaceImpl, U>(_ obj: T) -> UnsafeMutablePointer<U> {
return RawPointer(obj._default)
}
public func RawPointer<T: AbiInterfaceImpl, U>(_ obj: T?) -> UnsafeMutablePointer<U>? {
guard let obj else { return nil}
let result: UnsafeMutablePointer<U> = RawPointer(obj)
return result
}

View File

@ -0,0 +1,31 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
import CWinRT
public func RoGetActivationFactory<Factory: IInspectable>(_ activatableClassId: HString) throws -> Factory {
var iid = Factory.IID
let (factory) = try ComPtrs.initialize(to: C_IInspectable.self) { factoryAbi in
try CHECKED(RoGetActivationFactory(activatableClassId.get(), &iid, &factoryAbi))
}
return try factory!.queryInterface()
}
public func RoActivateInstance<Instance: IInspectable>(_ activatableClassId: HString) throws -> Instance {
let (instance) = try ComPtrs.initialize { instanceAbi in
try CHECKED(RoActivateInstance(activatableClassId.get(), &instanceAbi))
}
return try instance!.queryInterface()
}
// ISwiftImplemented is a marker interface for code-gen types which are created by swift/winrt. It's used to QI
// an IUnknown VTABLE to see whether we can unwrap this type as a known swift object. The class is marked final
// because it isn't intended to actually be implemented.
private var IID_ISwiftImplemented: WindowsFoundation.IID {
.init(Data1: 0xbfd14ad5, Data2: 0x950b, Data3: 0x4b82, Data4: ( 0x96, 0xc, 0x1, 0xf4, 0xf4, 0x77, 0x7e, 0x57 )) // BFD14AD5-950B-4B82-960C-01F4F4777E57
}
public final class ISwiftImplemented : IInspectable {
override public class var IID: WindowsFoundation.IID { IID_ISwiftImplemented }
}

View File

@ -0,0 +1,38 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import CWinRT
extension String {
public init(from hString: HSTRING?) {
var length: UINT32 = 0
let pwszBuffer: PCWSTR = WindowsGetStringRawBuffer(hString, &length)
self.init(decoding: UnsafeBufferPointer(start: pwszBuffer, count: Int(length)), as: UTF16.self)
}
public init(hString: HString) {
var length: UINT32 = 0
let pwszBuffer: PCWSTR = WindowsGetStringRawBuffer(hString.get(), &length)
self.init(decoding: UnsafeBufferPointer(start: pwszBuffer, count: Int(length)), as: UTF16.self)
}
}
extension Bool {
public init(from val: boolean) {
self.init(booleanLiteral: val != 0)
}
}
extension Character {
public init(from wchar: WCHAR) {
if let scalar = Unicode.Scalar(wchar) {
self.init(scalar)
} else {
self.init("")
}
}
}
extension UnsafeMutableRawPointer {
public static var none : UnsafeMutableRawPointer? { return nil }
}

View File

@ -0,0 +1,18 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import CWinRT
extension TrustLevel {
public static var BaseTrust: TrustLevel {
TrustLevel(rawValue: 0)
}
public static var PartialTrust: TrustLevel {
TrustLevel(rawValue: 1)
}
public static var FullTrust: TrustLevel {
TrustLevel(rawValue: 2)
}
}

View File

@ -0,0 +1,40 @@
import Foundation
actor WaitableEvent {
typealias Observer = @Sendable () -> Void
private var observer: Observer?
private var signaled = false
init() {}
/// Block until the signaled state is `true`.
func wait() async {
guard !signaled else { return }
guard observer == nil else {
#if DEBUG
preconditionFailure("message has already been waited on")
#else
return
#endif
}
await withCheckedContinuation { continuation in
observer = {
continuation.resume(returning: ())
}
}
}
/// Signals the event, unblocking any current or future waiter.
func signal() async {
guard !signaled else {
#if DEBUG
preconditionFailure("message already signaled")
#else
return
#endif
}
signaled = true
observer?()
}
}

View File

@ -0,0 +1,4 @@
// WinRTDelegateBridge specifies the contract for bridging between WinRT and Swift for event handlers and d
public protocol WinRTDelegateBridge<Handler>: AbiInterfaceBridge where SwiftProjection == Handler {
associatedtype Handler
}

View File

@ -0,0 +1,95 @@
import CWinRT
import Foundation
// Protocols for WinRT types that are used by public APIs
public protocol WinRTStruct {}
public protocol WinRTEnum {}
public protocol IWinRTObject: AnyObject {
var thisPtr: WindowsFoundation.IInspectable { get }
}
public protocol WinRTInterface: AnyObject, CustomQueryInterface {
}
open class WinRTClass : CustomQueryInterface, Equatable {
public init() {}
@_spi(WinRTInternal)
public init(_ ptr: WindowsFoundation.IInspectable) {
_inner = ptr
}
@_spi(WinRTInternal)
open func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == C_IInspectable.self {
return UnsafeMutableRawPointer(identity?.get())?.bindMemory(to: T.self, capacity: 1) ?? RawPointer(_inner)
}
if T.self == C_IUnknown.self {
return UnsafeMutableRawPointer(identity?.get())?.bindMemory(to: T.self, capacity: 1) ?? RawPointer(_inner)
}
return nil
}
@_spi(WinRTInternal)
public internal(set) var _inner: WindowsFoundation.IInspectable!
var identity: ComPtr<C_IInspectable>?
@_spi(WinRTImplements)
open func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
WindowsFoundation.queryInterface(self, iid)
}
deinit {
// ensure we release the identity pointer before releasing _inner. releasing the _inner
// cleans up the underlying COM object.
identity = nil
_inner = nil
}
}
public func ==<T: WinRTClass>(_ lhs: T, _ rhs: T) -> Bool {
return lhs.thisPtr == rhs.thisPtr
}
extension WinRTClass: IWinRTObject {
public var thisPtr: WindowsFoundation.IInspectable { try! _inner.QueryInterface() }
}
@_spi(WinRTInternal)
extension WinRTClass {
public func copyTo<Type>(_ ptr: UnsafeMutablePointer<UnsafeMutablePointer<Type>?>?) {
guard let ptr else { return }
let result: UnsafeMutablePointer<Type> = _getABI()!
result.withMemoryRebound(to: C_IInspectable.self, capacity: 1) {
_ = $0.pointee.lpVtbl.pointee.AddRef($0)
}
ptr.initialize(to: result)
}
public func GetRuntimeClassName() -> HString {
// always use the runtime class name of the inner WinRT object. the winui runtime will query for
// class names and if it isn't recognized, it will call out to IXamlMetadataProvider (IXMP)
// to get the associated XamlType. We aren't using Xaml for swift, so we don't actually
// need or want the framework to think it's dealing with custom types.
return try! _inner.GetRuntimeClassName()
}
fileprivate func aggregated() -> Bool { identity != nil }
// Get an interface for caching on a class. This method properly handles
// reference counting via releasing the reference added on the Swift object
// in the case of being aggregated. The wrapper still has the +1 ref on it,
// which will be released when the object is destroyed. We can safely let the
// objects be destroyed since _inner is destroyed last. Releasing _inner is what
// cleans up the underlying COM object.
public func getInterfaceForCaching<T: IUnknown>() -> T {
let ptr:T = try! _inner.QueryInterface()
if aggregated() {
Unmanaged.passUnretained(self).release()
}
return ptr
}
}

View File

@ -0,0 +1,255 @@
import CWinRT
import WinSDK
public protocol Initializable {
init()
}
public protocol HasIID {
static var IID: WindowsFoundation.IID { get }
}
public protocol AbiInterface {
associatedtype CABI
associatedtype SwiftABI : WindowsFoundation.IUnknown
}
// A protocol for defining a type which implements a WinRT interface and defines
// the swift <-> winrt translation. Note that AbiBridge doesn't depend on the SwiftABI,
// this is because not all conversions between the ABI and Swift have a SwiftABI implementation.
// For example, IReference<T> does not since those types are projected to T? in Swift.
public protocol AbiBridge {
associatedtype CABI
associatedtype SwiftProjection
static func makeAbi() -> CABI
static func from(abi: ComPtr<CABI>?) -> SwiftProjection?
}
public protocol ReferenceBridge : AbiBridge, HasIID {
}
public protocol AbiInterfaceBridge : AbiBridge & AbiInterface {
}
public protocol AbiInterfaceImpl<Bridge> {
associatedtype Bridge: AbiInterfaceBridge
var _default: Bridge.SwiftABI { get }
}
@_spi(WinRTInternal)
extension AbiInterfaceImpl {
public func getInterfaceForCaching<T: IUnknown>() -> T {
return try! _default.QueryInterface()
}
}
internal typealias AnyAbiInterfaceImpl<Bridge> = any AbiInterfaceImpl<Bridge>
public protocol WinRTAbiImpl<Bridge>: AbiInterfaceImpl where Bridge.SwiftABI: IInspectable {}
internal typealias AnyWinRTAbiImpl<Bridge> = any WinRTAbiImpl<Bridge>
internal protocol CustomAddRef {
func addRef()
func release()
}
// The WinRTWrapperBase class wraps an AbiBridge and is used for wrapping and unwrapping swift
// objects at the ABI layer. The contract for how to do this is defined by the AbiBridge protocol
open class WinRTWrapperBase<CInterface, Prototype> {
public struct ComObjectABI {
public var comInterface: CInterface
public var wrapper: Unmanaged<WinRTWrapperBase>?
}
public var instance: ComObjectABI
public var swiftObj: Prototype!
open class var IID: WindowsFoundation.IID { get { fatalError("not implemented") } }
public init(_ pointer: CInterface, _ impl: Prototype!) {
self.instance = ComObjectABI(comInterface: pointer)
self.swiftObj = impl
self.instance.wrapper = Unmanaged<WinRTWrapperBase>.passUnretained(self)
}
@_alwaysEmitIntoClient @inline(__always)
public func toABI<ResultType>(_ body: (UnsafeMutablePointer<CInterface>) throws -> ResultType)
throws -> ResultType {
try withUnsafeMutablePointer(to:&instance.comInterface){
return try body($0)
}
}
@_alwaysEmitIntoClient @inline(__always)
public func copyTo(_ ptr: UnsafeMutablePointer<UnsafeMutablePointer<CInterface>?>?) {
guard let ptr else { return }
// Use toABI as derived classes may override this to get the ABI pointer of the swift
// object they are holding onto
let abi: UnsafeMutablePointer<CInterface> = try! toABI { $0 }
abi.withMemoryRebound(to: C_IUnknown.self, capacity: 1) {
_ = $0.pointee.lpVtbl.pointee.AddRef($0)
}
ptr.initialize(to: abi)
}
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
// Use toABI as derived classes may override this to get the ABI pointer of the swift
// object they are holding onto
try! toABI {
$0.withMemoryRebound(to: C_IUnknown.self, capacity: 1) { pThis in
var iid = iid
let (ptr) = try? ComPtrs.initialize(to: C_IUnknown.self) { ptrAbi in
try CHECKED(pThis.pointee.lpVtbl.pointee.QueryInterface(pThis, &iid, &ptrAbi))
}
guard let ptr else { return nil }
return IUnknownRef(ptr)
}
}
}
public static func fromRaw(_ pUnk: UnsafeMutableRawPointer?) -> Unmanaged<WinRTWrapperBase>? {
guard let pUnk = pUnk else { return nil }
return pUnk.assumingMemoryBound(to: WinRTWrapperBase.ComObjectABI.self).pointee.wrapper
}
internal static func tryUnwrapFromBase(raw pUnk: UnsafeMutableRawPointer?) -> Prototype? {
guard let pUnk = pUnk else { return nil }
return fromRaw(pUnk)?.takeUnretainedValue().swiftObj
}
// When unwrapping from the abi, we want to see if the object has an existing implementation so we can use
// that to get to the existing swift object. if it doesn't exist then we can create a new implementation
public static func tryUnwrapFrom(abi pointer: ComPtr<CInterface>?) -> Prototype? {
guard let pointer = pointer else { return nil }
guard let wrapper: ISwiftImplemented = try? pointer.queryInterface() else { return nil }
let pUnk = UnsafeMutableRawPointer(wrapper.pUnk.borrow)
// try to get the original wrapper so we can get the apps implementation. if that doesn't
// exist, then return nil
guard let wrapper = pUnk.bindMemory(to: WinRTWrapperBase.ComObjectABI.self, capacity: 1).pointee.wrapper else { return nil }
return wrapper.takeUnretainedValue().swiftObj
}
public static func addRef(_ pUnk: UnsafeMutablePointer<CInterface>?) -> ULONG {
guard let unmanaged = fromRaw(pUnk) else { return 1 }
let wrapper = unmanaged.takeUnretainedValue()
_ = unmanaged.retain()
if let customAddRef = wrapper.swiftObj as? CustomAddRef {
customAddRef.addRef()
}
return ULONG(_getRetainCount(wrapper))
}
public static func release(_ pUnk: UnsafeMutablePointer<CInterface>?) -> ULONG {
guard let unmanaged = fromRaw(pUnk) else { return 1 }
let wrapper = unmanaged.takeUnretainedValue()
unmanaged.release()
if let customAddRef = wrapper.swiftObj as? CustomAddRef {
customAddRef.release()
}
return ULONG(_getRetainCount(wrapper))
}
fileprivate static func queryInterfaceBase(_ pUnk: UnsafeMutablePointer<CInterface>, _ riid: UnsafePointer<WindowsFoundation.IID>, _ result: UnsafeMutablePointer<UnsafeMutableRawPointer?>) -> HRESULT {
guard let instance = tryUnwrapFromBase(raw: pUnk) else { return E_FAIL }
do
{
switch riid.pointee {
case IID_IMarshal:
try makeMarshaler(IUnknownRef(ComPtr(pUnk)), result)
default:
guard let customQI = instance as? CustomQueryInterface,
let iUnknownRef = customQI.queryInterface(riid.pointee) else { return E_NOINTERFACE }
result.pointee = iUnknownRef.detach()
}
return S_OK
} catch {
return (error as? WindowsFoundation.Error)?.hr ?? E_FAIL
}
}
}
open class WinRTAbiBridgeWrapper<I: AbiBridge> : WinRTWrapperBase<I.CABI, I.SwiftProjection> {
public static func unwrapFrom(abi pointer: ComPtr<I.CABI>?) -> I.SwiftProjection? {
guard let pointer = pointer else { return nil }
guard let unwrapped = tryUnwrapFrom(abi: pointer) else { return I.from(abi: pointer) }
return unwrapped
}
open class func queryInterface(_ pUnk: UnsafeMutablePointer<I.CABI>?, _ riid: UnsafePointer<WindowsFoundation.IID>?, _ ppvObject: UnsafeMutablePointer<UnsafeMutableRawPointer?>?) -> HRESULT {
guard let pUnk, let riid, let ppvObject else { return E_INVALIDARG }
ppvObject.pointee = nil
switch riid.pointee {
case IUnknown.IID, IInspectable.IID, ISwiftImplemented.IID, IAgileObject.IID, Self.IID:
_ = addRef(pUnk)
ppvObject.pointee = UnsafeMutableRawPointer(pUnk)
return S_OK
default:
return super.queryInterfaceBase(pUnk, riid, ppvObject)
}
}
}
open class InterfaceWrapperBase<I: AbiInterfaceBridge> : WinRTAbiBridgeWrapper<I> {
override public class var IID: WindowsFoundation.IID { I.SwiftABI.IID }
public init?(_ impl: I.SwiftProjection?) {
guard let impl = impl else { return nil }
// try to see if already wrapping an ABI pointer and if so, use that
if let internalImpl = impl as? AnyAbiInterfaceImpl<I> {
let abi: UnsafeMutablePointer<I.CABI> = RawPointer(internalImpl)
super.init(abi.pointee, impl)
} else {
let abi = I.makeAbi()
super.init(abi, impl)
}
}
override public func toABI<ResultType>(_ body: (UnsafeMutablePointer<I.CABI>) throws -> ResultType)
throws -> ResultType {
// If this is an implementation then we're holding onto a WinRT object pointer, get that pointer
// and return that.
if let internalImpl = swiftObj as? AnyAbiInterfaceImpl<I> {
let abi: UnsafeMutablePointer<I.CABI> = RawPointer(internalImpl._default)
return try body(abi)
} else {
return try super.toABI(body)
}
}
public static func tryUnwrapFrom(raw pUnk: UnsafeMutableRawPointer?) -> I.SwiftProjection? {
tryUnwrapFromBase(raw: pUnk)
}
}
public class ReferenceWrapperBase<I: ReferenceBridge>: WinRTAbiBridgeWrapper<I> {
override public class var IID: WindowsFoundation.IID { I.IID }
public init?(_ value: I.SwiftProjection?) {
guard let value = value else { return nil }
let abi = I.makeAbi()
super.init(abi, value)
}
override public class func queryInterface(_ pUnk: UnsafeMutablePointer<I.CABI>?, _ riid: UnsafePointer<WindowsFoundation.IID>?, _ ppvObject: UnsafeMutablePointer<UnsafeMutableRawPointer?>?) -> HRESULT {
guard let pUnk, let riid, let ppvObject else { return E_INVALIDARG }
ppvObject.pointee = nil
switch riid.pointee {
case __ABI_Windows_Foundation.IPropertyValueWrapper.IID:
guard let value = tryUnwrapFrom(raw: pUnk),
let wrapper = __ABI_Windows_Foundation.IPropertyValueWrapper(__IMPL_Windows_Foundation.IPropertyValueImpl(value: value)) else { return E_FAIL }
guard let iUnk = wrapper.queryInterface(__ABI_Windows_Foundation.IPropertyValueWrapper.IID) else { return E_NOINTERFACE }
ppvObject.pointee = iUnk.detach()
return S_OK
default:
return super.queryInterface(pUnk, riid, ppvObject)
}
}
public static func tryUnwrapFrom(raw pUnk: UnsafeMutableRawPointer?) -> I.SwiftProjection? {
tryUnwrapFromBase(raw: pUnk)
}
}

View File

@ -0,0 +1,39 @@
// Copyright © 2021 Saleem Abdulrasool <compnerd@compnerd.org>
// SPDX-License-Identifier: BSD-3
import WinSDK
public typealias LPVOID = UnsafeMutableRawPointer
// winnt.h
@_transparent
internal func MAKELANGID(_ p: WORD, _ s: WORD) -> DWORD {
return DWORD((s << 10) | p)
}
extension boolean {
public init(from val: Bool) {
let value : boolean = val ? 1 : 0
self.init(value)
}
}
extension HWND {
public init?(from val: UInt64) {
self.init(HWND(bitPattern: UInt(val)))
}
}
extension WCHAR {
public init(from val: Character) {
// FIXME(compnerd) this needs to be a failable initializer as there may be a
// surrogate pair required.
self.init(val.utf16.first!)
}
}
// stdlib.h
public var MB_MAX : Int {
Int(___mb_cur_max_func())
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,457 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
public enum __IMPL_Windows_Foundation {
public enum IAsyncActionBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIAsyncAction
public typealias SwiftABI = __ABI_Windows_Foundation.IAsyncAction
public typealias SwiftProjection = AnyIAsyncAction
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IAsyncActionImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IAsyncActionVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IAsyncActionImpl: IAsyncAction, WinRTAbiImpl {
fileprivate typealias Bridge = IAsyncActionBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.getresults)
fileprivate func getResults() throws {
try _default.GetResultsImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.completed)
fileprivate var completed : AsyncActionCompletedHandler! {
get { try! _default.get_CompletedImpl() }
set { try! _default.put_CompletedImpl(newValue) }
}
private lazy var _IAsyncInfo: __ABI_Windows_Foundation.IAsyncInfo! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.cancel)
fileprivate func cancel() throws {
try _IAsyncInfo.CancelImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.close)
fileprivate func close() throws {
try _IAsyncInfo.CloseImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.errorcode)
fileprivate var errorCode : HRESULT {
get { try! _IAsyncInfo.get_ErrorCodeImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.id)
fileprivate var id : UInt32 {
get { try! _IAsyncInfo.get_IdImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.status)
fileprivate var status : AsyncStatus {
get { try! _IAsyncInfo.get_StatusImpl() }
}
}
public enum IAsyncInfoBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIAsyncInfo
public typealias SwiftABI = __ABI_Windows_Foundation.IAsyncInfo
public typealias SwiftProjection = AnyIAsyncInfo
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IAsyncInfoImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IAsyncInfoVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IAsyncInfoImpl: IAsyncInfo, WinRTAbiImpl {
fileprivate typealias Bridge = IAsyncInfoBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.cancel)
fileprivate func cancel() throws {
try _default.CancelImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.close)
fileprivate func close() throws {
try _default.CloseImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.errorcode)
fileprivate var errorCode : HRESULT {
get { try! _default.get_ErrorCodeImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.id)
fileprivate var id : UInt32 {
get { try! _default.get_IdImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.status)
fileprivate var status : AsyncStatus {
get { try! _default.get_StatusImpl() }
}
}
public enum IClosableBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIClosable
public typealias SwiftABI = __ABI_Windows_Foundation.IClosable
public typealias SwiftProjection = AnyIClosable
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IClosableImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IClosableVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IClosableImpl: IClosable, WinRTAbiImpl {
fileprivate typealias Bridge = IClosableBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iclosable.close)
fileprivate func close() throws {
try _default.CloseImpl()
}
}
public enum IGetActivationFactoryBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIGetActivationFactory
public typealias SwiftABI = __ABI_Windows_Foundation.IGetActivationFactory
public typealias SwiftProjection = AnyIGetActivationFactory
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IGetActivationFactoryImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IGetActivationFactoryVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IGetActivationFactoryImpl: IGetActivationFactory, WinRTAbiImpl {
fileprivate typealias Bridge = IGetActivationFactoryBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.igetactivationfactory.getactivationfactory)
fileprivate func getActivationFactory(_ activatableClassId: String) throws -> Any! {
try _default.GetActivationFactoryImpl(activatableClassId)
}
}
public enum IMemoryBufferBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIMemoryBuffer
public typealias SwiftABI = __ABI_Windows_Foundation.IMemoryBuffer
public typealias SwiftProjection = AnyIMemoryBuffer
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IMemoryBufferImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IMemoryBufferVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IMemoryBufferImpl: IMemoryBuffer, WinRTAbiImpl {
fileprivate typealias Bridge = IMemoryBufferBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybuffer.createreference)
fileprivate func createReference() throws -> AnyIMemoryBufferReference! {
try _default.CreateReferenceImpl()
}
private lazy var _IClosable: __ABI_Windows_Foundation.IClosable! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybuffer.close)
fileprivate func close() throws {
try _IClosable.CloseImpl()
}
}
public enum IMemoryBufferReferenceBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIMemoryBufferReference
public typealias SwiftABI = __ABI_Windows_Foundation.IMemoryBufferReference
public typealias SwiftProjection = AnyIMemoryBufferReference
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IMemoryBufferReferenceImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IMemoryBufferReferenceVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IMemoryBufferReferenceImpl: IMemoryBufferReference, WinRTAbiImpl {
fileprivate typealias Bridge = IMemoryBufferReferenceBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference.capacity)
fileprivate var capacity : UInt32 {
get { try! _default.get_CapacityImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference.closed)
fileprivate lazy var closed : Event<TypedEventHandler<IMemoryBufferReference?, Any?>> = {
.init(
add: { [weak self] in
guard let this = self?._default else { return .init() }
return try! this.add_ClosedImpl($0)
},
remove: { [weak self] in
try? self?._default.remove_ClosedImpl($0)
}
)
}()
private lazy var _IClosable: __ABI_Windows_Foundation.IClosable! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference.close)
fileprivate func close() throws {
try _IClosable.CloseImpl()
}
private lazy var _IMemoryBufferByteAccess: __ABI_.IMemoryBufferByteAccess! = getInterfaceForCaching()
fileprivate var buffer: UnsafeMutableBufferPointer<UInt8>? {
get throws {
let bufferByteAccess: WindowsFoundation.__ABI_.IMemoryBufferByteAccess = try _IMemoryBufferByteAccess.QueryInterface()
return try bufferByteAccess.Buffer()
}
}
}
public enum IPropertyValueBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIPropertyValue
public typealias SwiftABI = __ABI_Windows_Foundation.IPropertyValue
public typealias SwiftProjection = AnyIPropertyValue
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IPropertyValueImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IPropertyValueVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
public class IPropertyValueImpl : IPropertyValue, IReference {
public typealias T = Any
var _value: Any
var propertyType : PropertyType
fileprivate init(_ abi: ComPtr<__x_ABI_CWindows_CFoundation_CIPropertyValue>) { fatalError("not implemented") }
public init(value: Any) {
_value = value
if _value is Int32 {
propertyType = .int32
} else if _value is UInt8 {
propertyType = .uint8
} else if _value is Int16 {
propertyType = .int16
} else if _value is UInt32 {
propertyType = .uint32
} else if _value is Int64 {
propertyType = .int64
} else if _value is UInt64 {
propertyType = .uint64
} else if _value is Float {
propertyType = .single
} else if _value is Double {
propertyType = .double
} else if _value is Character {
propertyType = .char16
} else if _value is Bool {
propertyType = .boolean
} else if _value is DateTime {
propertyType = .dateTime
} else if _value is TimeSpan {
propertyType = .timeSpan
} else if _value is IWinRTObject {
propertyType = .inspectable
} else if _value is IInspectable {
propertyType = .inspectable
} else {
propertyType = .otherType
}
}
public var type: PropertyType { propertyType }
public var isNumericScalar: Bool {
switch propertyType {
case .int16, .int32, .int64, .uint8, .uint16, .uint32, .uint64, .single, .double: return true
default: return false
}
}
public var value: Any { _value }
public func getUInt8() -> UInt8 { _value as! UInt8 }
public func getInt16() -> Int16 { _value as! Int16 }
public func getUInt16() -> UInt16 { _value as! UInt16 }
public func getInt32() -> Int32 { _value as! Int32 }
public func getUInt32() -> UInt32 { _value as! UInt32 }
public func getInt64() -> Int64 { _value as! Int64 }
public func getUInt64() -> UInt64 { _value as! UInt64 }
public func getSingle() -> Float { _value as! Float }
public func getDouble() -> Double { _value as! Double }
public func getChar16() -> Character { _value as! Character }
public func getBoolean() -> Bool { _value as! Bool }
public func getString() -> String { _value as! String }
public func getGuid() -> Foundation.UUID { _value as! Foundation.UUID }
public func getDateTime() -> DateTime { _value as! DateTime }
public func getTimeSpan() -> TimeSpan { _value as! TimeSpan }
public func getPoint() -> Point { _value as! Point }
public func getSize() -> Size { _value as! Size }
public func getRect() -> Rect { _value as! Rect }
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
guard iid == __ABI_Windows_Foundation.IPropertyValueWrapper.IID else { return nil }
guard let thisAsIPropValue = __ABI_Windows_Foundation.IPropertyValueWrapper(self) else { fatalError("creating non-nil wrapper shouldn't fail") }
return thisAsIPropValue.queryInterface(iid)
}
}
public enum IStringableBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIStringable
public typealias SwiftABI = __ABI_Windows_Foundation.IStringable
public typealias SwiftProjection = AnyIStringable
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IStringableImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IStringableVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IStringableImpl: IStringable, WinRTAbiImpl {
fileprivate typealias Bridge = IStringableBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.istringable.tostring)
fileprivate func toString() throws -> String {
try _default.ToStringImpl()
}
}
public enum IWwwFormUrlDecoderEntryBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CIWwwFormUrlDecoderEntry
public typealias SwiftABI = __ABI_Windows_Foundation.IWwwFormUrlDecoderEntry
public typealias SwiftProjection = AnyIWwwFormUrlDecoderEntry
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IWwwFormUrlDecoderEntryImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation.IWwwFormUrlDecoderEntryVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IWwwFormUrlDecoderEntryImpl: IWwwFormUrlDecoderEntry, WinRTAbiImpl {
fileprivate typealias Bridge = IWwwFormUrlDecoderEntryBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iwwwformurldecoderentry.name)
fileprivate var name : String {
get { try! _default.get_NameImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iwwwformurldecoderentry.value)
fileprivate var value : String {
get { try! _default.get_ValueImpl() }
}
}
public class AsyncActionCompletedHandlerBridge : WinRTDelegateBridge {
public typealias Handler = AsyncActionCompletedHandler
public typealias CABI = __x_ABI_CWindows_CFoundation_CIAsyncActionCompletedHandler
public typealias SwiftABI = __ABI_Windows_Foundation.AsyncActionCompletedHandler
public static func from(abi: ComPtr<CABI>?) -> Handler? {
guard let abi = abi else { return nil }
let _default = SwiftABI(abi)
let handler: Handler = { (asyncInfo, asyncStatus) in
try! _default.InvokeImpl(asyncInfo, asyncStatus)
}
return handler
}
}
public class DeferralCompletedHandlerBridge : WinRTDelegateBridge {
public typealias Handler = DeferralCompletedHandler
public typealias CABI = __x_ABI_CWindows_CFoundation_CIDeferralCompletedHandler
public typealias SwiftABI = __ABI_Windows_Foundation.DeferralCompletedHandler
public static func from(abi: ComPtr<CABI>?) -> Handler? {
guard let abi = abi else { return nil }
let _default = SwiftABI(abi)
let handler: Handler = { () in
try! _default.InvokeImpl()
}
return handler
}
}
}

View File

@ -0,0 +1,166 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
private var IID___x_ABI_C__FIIterable_1_T: WindowsFoundation.IID {
.init(Data1: 0xFAA585EA, Data2: 0x6214, Data3: 0x4217, Data4: ( 0xAF,0xDA,0x7F,0x46,0xDE,0x58,0x69,0xB3 ))// FAA585EA-6214-4217-AFDA-7F46DE5869B3
}
private var IID___x_ABI_C__FIIterator_1_T: WindowsFoundation.IID {
.init(Data1: 0x6A79E863, Data2: 0x4300, Data3: 0x459A, Data4: ( 0x99,0x66,0xCB,0xB6,0x60,0x96,0x3E,0xE1 ))// 6A79E863-4300-459A-9966-CBB660963EE1
}
private var IID___x_ABI_C__FIKeyValuePair_2_K_V: WindowsFoundation.IID {
.init(Data1: 0x02B51929, Data2: 0xC1C4, Data3: 0x4A7E, Data4: ( 0x89,0x40,0x03,0x12,0xB5,0xC1,0x85,0x00 ))// 02B51929-C1C4-4A7E-8940-0312B5C18500
}
private var IID___x_ABI_C__FIMapChangedEventArgs_1_K: WindowsFoundation.IID {
.init(Data1: 0x9939F4DF, Data2: 0x050A, Data3: 0x4C0F, Data4: ( 0xAA,0x60,0x77,0x07,0x5F,0x9C,0x47,0x77 ))// 9939F4DF-050A-4C0F-AA60-77075F9C4777
}
private var IID___x_ABI_C__FIMapView_2_K_V: WindowsFoundation.IID {
.init(Data1: 0xE480CE40, Data2: 0xA338, Data3: 0x4ADA, Data4: ( 0xAD,0xCF,0x27,0x22,0x72,0xE4,0x8C,0xB9 ))// E480CE40-A338-4ADA-ADCF-272272E48CB9
}
private var IID___x_ABI_C__FIMap_2_K_V: WindowsFoundation.IID {
.init(Data1: 0x3C2925FE, Data2: 0x8519, Data3: 0x45C1, Data4: ( 0xAA,0x79,0x19,0x7B,0x67,0x18,0xC1,0xC1 ))// 3C2925FE-8519-45C1-AA79-197B6718C1C1
}
private var IID___x_ABI_C__FIObservableMap_2_K_V: WindowsFoundation.IID {
.init(Data1: 0x65DF2BF5, Data2: 0xBF39, Data3: 0x41B5, Data4: ( 0xAE,0xBC,0x5A,0x9D,0x86,0x5E,0x47,0x2B ))// 65DF2BF5-BF39-41B5-AEBC-5A9D865E472B
}
private var IID___x_ABI_C__FIObservableVector_1_T: WindowsFoundation.IID {
.init(Data1: 0x5917EB53, Data2: 0x50B4, Data3: 0x4A0D, Data4: ( 0xB3,0x09,0x65,0x86,0x2B,0x3F,0x1D,0xBC ))// 5917EB53-50B4-4A0D-B309-65862B3F1DBC
}
private var IID___x_ABI_CWindows_CFoundation_CCollections_CIPropertySet: WindowsFoundation.IID {
.init(Data1: 0x8A43ED9F, Data2: 0xF4E6, Data3: 0x4421, Data4: ( 0xAC,0xF9,0x1D,0xAB,0x29,0x86,0x82,0x0C ))// 8A43ED9F-F4E6-4421-ACF9-1DAB2986820C
}
private var IID___x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgs: WindowsFoundation.IID {
.init(Data1: 0x575933DF, Data2: 0x34FE, Data3: 0x4480, Data4: ( 0xAF,0x15,0x07,0x69,0x1F,0x3D,0x5D,0x9B ))// 575933DF-34FE-4480-AF15-07691F3D5D9B
}
private var IID___x_ABI_C__FIVectorView_1_T: WindowsFoundation.IID {
.init(Data1: 0xBBE1FA4C, Data2: 0xB0E3, Data3: 0x4583, Data4: ( 0xBA,0xEF,0x1F,0x1B,0x2E,0x48,0x3E,0x56 ))// BBE1FA4C-B0E3-4583-BAEF-1F1B2E483E56
}
private var IID___x_ABI_C__FIVector_1_T: WindowsFoundation.IID {
.init(Data1: 0x913337E9, Data2: 0x11A1, Data3: 0x4345, Data4: ( 0xA3,0xA2,0x4E,0x7F,0x95,0x6E,0x22,0x2D ))// 913337E9-11A1-4345-A3A2-4E7F956E222D
}
private var IID___x_ABI_C__FMapChangedEventHandler_2_K_V: WindowsFoundation.IID {
.init(Data1: 0x179517F3, Data2: 0x94EE, Data3: 0x41F8, Data4: ( 0xBD,0xDC,0x76,0x8A,0x89,0x55,0x44,0xF3 ))// 179517F3-94EE-41F8-BDDC-768A895544F3
}
private var IID___x_ABI_C__FVectorChangedEventHandler_1_T: WindowsFoundation.IID {
.init(Data1: 0x0C051752, Data2: 0x9FBF, Data3: 0x4C70, Data4: ( 0xAA,0x0C,0x0E,0x4C,0x82,0xD9,0xA7,0x61 ))// 0C051752-9FBF-4C70-AA0C-0E4C82D9A761
}
public enum __ABI_Windows_Foundation_Collections {
public class IPropertySet: WindowsFoundation.IInspectable {
override public class var IID: WindowsFoundation.IID { IID___x_ABI_CWindows_CFoundation_CCollections_CIPropertySet }
}
internal static var IPropertySetVTable: __x_ABI_CWindows_CFoundation_CCollections_CIPropertySetVtbl = .init(
QueryInterface: { IPropertySetWrapper.queryInterface($0, $1, $2) },
AddRef: { IPropertySetWrapper.addRef($0) },
Release: { IPropertySetWrapper.release($0) },
GetIids: {
let size = MemoryLayout<WindowsFoundation.IID>.size
let iids = CoTaskMemAlloc(UInt64(size) * 6).assumingMemoryBound(to: WindowsFoundation.IID.self)
iids[0] = IUnknown.IID
iids[1] = IInspectable.IID
iids[2] = __ABI_Windows_Foundation_Collections.IPropertySetWrapper.IID
iids[3] = WindowsFoundation.__x_ABI_C__FIObservableMap_2_HSTRING_IInspectableWrapper.IID
iids[4] = WindowsFoundation.__x_ABI_C__FIMap_2_HSTRING_IInspectableWrapper.IID
iids[5] = WindowsFoundation.__x_ABI_C__FIIterable_1___x_ABI_C__FIKeyValuePair_2_HSTRING_IInspectableWrapper.IID
$1!.pointee = 6
$2!.pointee = iids
return S_OK
},
GetRuntimeClassName: {
_ = $0
let hstring = try! HString("Windows.Foundation.Collections.IPropertySet").detach()
$1!.pointee = hstring
return S_OK
},
GetTrustLevel: {
_ = $0
$1!.pointee = TrustLevel(rawValue: 0)
return S_OK
}
)
public typealias IPropertySetWrapper = InterfaceWrapperBase<__IMPL_Windows_Foundation_Collections.IPropertySetBridge>
public class IVectorChangedEventArgs: WindowsFoundation.IInspectable {
override public class var IID: WindowsFoundation.IID { IID___x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgs }
open func get_CollectionChangeImpl() throws -> WindowsFoundation.CollectionChange {
var value: __x_ABI_CWindows_CFoundation_CCollections_CCollectionChange = .init(0)
_ = try perform(as: __x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgs.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.get_CollectionChange(pThis, &value))
}
return value
}
open func get_IndexImpl() throws -> UInt32 {
var value: UINT32 = 0
_ = try perform(as: __x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgs.self) { pThis in
try CHECKED(pThis.pointee.lpVtbl.pointee.get_Index(pThis, &value))
}
return value
}
}
internal static var IVectorChangedEventArgsVTable: __x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgsVtbl = .init(
QueryInterface: { IVectorChangedEventArgsWrapper.queryInterface($0, $1, $2) },
AddRef: { IVectorChangedEventArgsWrapper.addRef($0) },
Release: { IVectorChangedEventArgsWrapper.release($0) },
GetIids: {
let size = MemoryLayout<WindowsFoundation.IID>.size
let iids = CoTaskMemAlloc(UInt64(size) * 3).assumingMemoryBound(to: WindowsFoundation.IID.self)
iids[0] = IUnknown.IID
iids[1] = IInspectable.IID
iids[2] = __ABI_Windows_Foundation_Collections.IVectorChangedEventArgsWrapper.IID
$1!.pointee = 3
$2!.pointee = iids
return S_OK
},
GetRuntimeClassName: {
_ = $0
let hstring = try! HString("Windows.Foundation.Collections.IVectorChangedEventArgs").detach()
$1!.pointee = hstring
return S_OK
},
GetTrustLevel: {
_ = $0
$1!.pointee = TrustLevel(rawValue: 0)
return S_OK
},
get_CollectionChange: {
guard let __unwrapped__instance = IVectorChangedEventArgsWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let value = __unwrapped__instance.collectionChange
$1?.initialize(to: value)
return S_OK
},
get_Index: {
guard let __unwrapped__instance = IVectorChangedEventArgsWrapper.tryUnwrapFrom(raw: $0) else { return E_INVALIDARG }
let value = __unwrapped__instance.index
$1?.initialize(to: value)
return S_OK
}
)
public typealias IVectorChangedEventArgsWrapper = InterfaceWrapperBase<__IMPL_Windows_Foundation_Collections.IVectorChangedEventArgsBridge>
}

View File

@ -0,0 +1,126 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
public enum __IMPL_Windows_Foundation_Collections {
public enum IPropertySetBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CCollections_CIPropertySet
public typealias SwiftABI = __ABI_Windows_Foundation_Collections.IPropertySet
public typealias SwiftProjection = AnyIPropertySet
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IPropertySetImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation_Collections.IPropertySetVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IPropertySetImpl: IPropertySet, WinRTAbiImpl {
fileprivate typealias Bridge = IPropertySetBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
public typealias K = String
public typealias V = Any?
public typealias T = AnyIKeyValuePair<String, Any?>?
private lazy var _IObservableMap: IObservableMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.mapchanged)
fileprivate lazy var mapChanged : Event<MapChangedEventHandler<String, Any?>> = {
.init(
add: { [weak self] in
guard let this = self?._IObservableMap else { return .init() }
return try! this.add_MapChangedImpl($0)
},
remove: { [weak self] in
try? self?._IObservableMap.remove_MapChangedImpl($0)
}
)
}()
private lazy var _IMap: IMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.lookup)
fileprivate func lookup(_ key: String) -> Any? {
try! _IMap.LookupImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.haskey)
fileprivate func hasKey(_ key: String) -> Bool {
try! _IMap.HasKeyImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.getview)
fileprivate func getView() -> AnyIMapView<String, Any?>? {
try! _IMap.GetViewImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.insert)
fileprivate func insert(_ key: String, _ value: Any?) -> Bool {
try! _IMap.InsertImpl(key, value)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.remove)
fileprivate func remove(_ key: String) {
try! _IMap.RemoveImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.clear)
fileprivate func clear() {
try! _IMap.ClearImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.size)
fileprivate var size : UInt32 {
get { try! _IMap.get_SizeImpl() }
}
private lazy var _IIterable: IIterableIKeyValuePairString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset.first)
fileprivate func first() -> AnyIIterator<AnyIKeyValuePair<String, Any?>?>? {
try! _IIterable.FirstImpl()
}
}
public enum IVectorChangedEventArgsBridge : AbiInterfaceBridge {
public typealias CABI = __x_ABI_CWindows_CFoundation_CCollections_CIVectorChangedEventArgs
public typealias SwiftABI = __ABI_Windows_Foundation_Collections.IVectorChangedEventArgs
public typealias SwiftProjection = AnyIVectorChangedEventArgs
public static func from(abi: ComPtr<CABI>?) -> SwiftProjection? {
guard let abi = abi else { return nil }
return IVectorChangedEventArgsImpl(abi)
}
public static func makeAbi() -> CABI {
let vtblPtr = withUnsafeMutablePointer(to: &__ABI_Windows_Foundation_Collections.IVectorChangedEventArgsVTable) { $0 }
return .init(lpVtbl: vtblPtr)
}
}
fileprivate class IVectorChangedEventArgsImpl: IVectorChangedEventArgs, WinRTAbiImpl {
fileprivate typealias Bridge = IVectorChangedEventArgsBridge
fileprivate let _default: Bridge.SwiftABI
fileprivate var thisPtr: WindowsFoundation.IInspectable { _default }
fileprivate init(_ fromAbi: ComPtr<Bridge.CABI>) {
_default = Bridge.SwiftABI(fromAbi)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorchangedeventargs.collectionchange)
fileprivate var collectionChange : CollectionChange {
get { try! _default.get_CollectionChangeImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorchangedeventargs.index)
fileprivate var index : UInt32 {
get { try! _default.get_IndexImpl() }
}
}
}

View File

@ -0,0 +1,504 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.collectionchange)
public typealias CollectionChange = __x_ABI_CWindows_CFoundation_CCollections_CCollectionChange
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset)
public final class PropertySet : WinRTClass, IObservableMap, IMap, IIterable, IPropertySet {
public typealias K = String
public typealias V = Any?
public typealias T = AnyIKeyValuePair<String, Any?>?
private typealias SwiftABI = __ABI_Windows_Foundation_Collections.IPropertySet
private typealias CABI = __x_ABI_CWindows_CFoundation_CCollections_CIPropertySet
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CCollections_CIPropertySet>?) -> PropertySet? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
override public init() {
super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.PropertySet")))
}
private lazy var _IObservableMap: IObservableMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.mapchanged)
public lazy var mapChanged : Event<MapChangedEventHandler<String, Any?>> = {
.init(
add: { [weak self] in
guard let this = self?._IObservableMap else { return .init() }
return try! this.add_MapChangedImpl($0)
},
remove: { [weak self] in
try? self?._IObservableMap.remove_MapChangedImpl($0)
}
)
}()
private lazy var _IMap: IMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.lookup)
public func lookup(_ key: String) -> Any? {
try! _IMap.LookupImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.haskey)
public func hasKey(_ key: String) -> Bool {
try! _IMap.HasKeyImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.getview)
public func getView() -> AnyIMapView<String, Any?>? {
try! _IMap.GetViewImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.insert)
public func insert(_ key: String, _ value: Any?) -> Bool {
try! _IMap.InsertImpl(key, value)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.remove)
public func remove(_ key: String) {
try! _IMap.RemoveImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.clear)
public func clear() {
try! _IMap.ClearImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.size)
public var size : UInt32 {
get { try! _IMap.get_SizeImpl() }
}
private lazy var _IIterable: IIterableIKeyValuePairString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.propertyset.first)
public func first() -> AnyIIterator<AnyIKeyValuePair<String, Any?>?>? {
try! _IIterable.FirstImpl()
}
deinit {
_IObservableMap = nil
_IMap = nil
_IIterable = nil
_default = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap)
public final class StringMap : WinRTClass, IMap, IIterable, IObservableMap {
public typealias K = String
public typealias V = String
public typealias T = AnyIKeyValuePair<String, String>?
private typealias SwiftABI = WindowsFoundation.IMapString_String
private typealias CABI = __x_ABI_C__FIMap_2_HSTRING_HSTRING
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_C__FIMap_2_HSTRING_HSTRING>?) -> StringMap? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
override public init() {
super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.StringMap")))
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.lookup)
public func lookup(_ key: String) -> String {
try! _default.LookupImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.haskey)
public func hasKey(_ key: String) -> Bool {
try! _default.HasKeyImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.getview)
public func getView() -> AnyIMapView<String, String>? {
try! _default.GetViewImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.insert)
public func insert(_ key: String, _ value: String) -> Bool {
try! _default.InsertImpl(key, value)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.remove)
public func remove(_ key: String) {
try! _default.RemoveImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.clear)
public func clear() {
try! _default.ClearImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.size)
public var size : UInt32 {
get { try! _default.get_SizeImpl() }
}
private lazy var _IIterable: IIterableIKeyValuePairString_String! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.first)
public func first() -> AnyIIterator<AnyIKeyValuePair<String, String>?>? {
try! _IIterable.FirstImpl()
}
private lazy var _IObservableMap: IObservableMapString_String! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.mapchanged)
public lazy var mapChanged : Event<MapChangedEventHandler<String, String>> = {
.init(
add: { [weak self] in
guard let this = self?._IObservableMap else { return .init() }
return try! this.add_MapChangedImpl($0)
},
remove: { [weak self] in
try? self?._IObservableMap.remove_MapChangedImpl($0)
}
)
}()
deinit {
_default = nil
_IIterable = nil
_IObservableMap = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset)
public final class ValueSet : WinRTClass, IObservableMap, IMap, IIterable, IPropertySet {
public typealias K = String
public typealias V = Any?
public typealias T = AnyIKeyValuePair<String, Any?>?
private typealias SwiftABI = __ABI_Windows_Foundation_Collections.IPropertySet
private typealias CABI = __x_ABI_CWindows_CFoundation_CCollections_CIPropertySet
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CCollections_CIPropertySet>?) -> ValueSet? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
override public init() {
super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.ValueSet")))
}
private lazy var _IObservableMap: IObservableMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.mapchanged)
public lazy var mapChanged : Event<MapChangedEventHandler<String, Any?>> = {
.init(
add: { [weak self] in
guard let this = self?._IObservableMap else { return .init() }
return try! this.add_MapChangedImpl($0)
},
remove: { [weak self] in
try? self?._IObservableMap.remove_MapChangedImpl($0)
}
)
}()
private lazy var _IMap: IMapString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.lookup)
public func lookup(_ key: String) -> Any? {
try! _IMap.LookupImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.haskey)
public func hasKey(_ key: String) -> Bool {
try! _IMap.HasKeyImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.getview)
public func getView() -> AnyIMapView<String, Any?>? {
try! _IMap.GetViewImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.insert)
public func insert(_ key: String, _ value: Any?) -> Bool {
try! _IMap.InsertImpl(key, value)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.remove)
public func remove(_ key: String) {
try! _IMap.RemoveImpl(key)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.clear)
public func clear() {
try! _IMap.ClearImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.size)
public var size : UInt32 {
get { try! _IMap.get_SizeImpl() }
}
private lazy var _IIterable: IIterableIKeyValuePairString_Any! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.valueset.first)
public func first() -> AnyIIterator<AnyIKeyValuePair<String, Any?>?>? {
try! _IIterable.FirstImpl()
}
deinit {
_IObservableMap = nil
_IMap = nil
_IIterable = nil
_default = nil
}
}
public typealias MapChangedEventHandler<K,V> = (AnyIObservableMap<K, V>?, AnyIMapChangedEventArgs<K>?) -> ()
public typealias VectorChangedEventHandler<T> = (AnyIObservableVector<T>?, AnyIVectorChangedEventArgs?) -> ()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterable-1)
public protocol IIterable<T> : WinRTInterface {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterable-1.first)
func first() -> WindowsFoundation.AnyIIterator<T>?
}
public typealias AnyIIterable<T> = any IIterable<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterator-1)
public protocol IIterator<T> : WinRTInterface {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterator-1.movenext)
func moveNext() -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterator-1.current)
var current: T { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iiterator-1.hascurrent)
var hasCurrent: Bool { get }
}
public typealias AnyIIterator<T> = any IIterator<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ikeyvaluepair-2)
public protocol IKeyValuePair<K,V> : WinRTInterface {
associatedtype K
associatedtype V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ikeyvaluepair-2.key)
var key: K { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ikeyvaluepair-2.value)
var value: V { get }
}
public typealias AnyIKeyValuePair<K,V> = any IKeyValuePair<K,V>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapchangedeventargs-1)
public protocol IMapChangedEventArgs<K> : WinRTInterface {
associatedtype K
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapchangedeventargs-1.collectionchange)
var collectionChange: WindowsFoundation.CollectionChange { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapchangedeventargs-1.key)
var key: K { get }
}
public typealias AnyIMapChangedEventArgs<K> = any IMapChangedEventArgs<K>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapview-2)
public protocol IMapView<K,V> : IIterable where T == AnyIKeyValuePair<K,V>? {
associatedtype K
associatedtype V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapview-2.lookup)
func lookup(_ key: K) -> V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapview-2.haskey)
func hasKey(_ key: K) -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapview-2.split)
func split(_ first: inout WindowsFoundation.AnyIMapView<K, V>?, _ second: inout WindowsFoundation.AnyIMapView<K, V>?)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imapview-2.size)
var size: UInt32 { get }
}
public typealias AnyIMapView<K,V> = any IMapView<K,V>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2)
public protocol IMap<K,V> : IIterable where T == AnyIKeyValuePair<K,V>? {
associatedtype K
associatedtype V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.lookup)
func lookup(_ key: K) -> V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.haskey)
func hasKey(_ key: K) -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.getview)
func getView() -> WindowsFoundation.AnyIMapView<K, V>?
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.insert)
func insert(_ key: K, _ value: V) -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.remove)
func remove(_ key: K)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.clear)
func clear()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.imap-2.size)
var size: UInt32 { get }
}
public typealias AnyIMap<K,V> = any IMap<K,V>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iobservablemap-2)
public protocol IObservableMap<K,V> : IIterable, IMap {
associatedtype K
associatedtype V
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iobservablemap-2.mapchanged)
var mapChanged: Event<MapChangedEventHandler<K,V>> { get }
}
public typealias AnyIObservableMap<K,V> = any IObservableMap<K,V>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iobservablevector-1)
public protocol IObservableVector<T> : IIterable, IVector {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.iobservablevector-1.vectorchanged)
var vectorChanged: Event<VectorChangedEventHandler<T>> { get }
}
public typealias AnyIObservableVector<T> = any IObservableVector<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ipropertyset)
public protocol IPropertySet : IObservableMap<String, Any?>, IMap<String, Any?>, IIterable<AnyIKeyValuePair<String, Any?>?> {
}
extension IPropertySet {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation_Collections.IPropertySetWrapper.IID:
let wrapper = __ABI_Windows_Foundation_Collections.IPropertySetWrapper(self)
return wrapper!.queryInterface(iid)
case WindowsFoundation.__x_ABI_C__FIObservableMap_2_HSTRING_IInspectableWrapper.IID:
let wrapper = WindowsFoundation.__x_ABI_C__FIObservableMap_2_HSTRING_IInspectableWrapper(self)
return wrapper!.queryInterface(iid)
case WindowsFoundation.__x_ABI_C__FIMap_2_HSTRING_IInspectableWrapper.IID:
let wrapper = WindowsFoundation.__x_ABI_C__FIMap_2_HSTRING_IInspectableWrapper(self)
return wrapper!.queryInterface(iid)
case WindowsFoundation.__x_ABI_C__FIIterable_1___x_ABI_C__FIKeyValuePair_2_HSTRING_IInspectableWrapper.IID:
let wrapper = WindowsFoundation.__x_ABI_C__FIIterable_1___x_ABI_C__FIKeyValuePair_2_HSTRING_IInspectableWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIPropertySet = any IPropertySet
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorchangedeventargs)
public protocol IVectorChangedEventArgs : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorchangedeventargs.collectionchange)
var collectionChange: WindowsFoundation.CollectionChange { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorchangedeventargs.index)
var index: UInt32 { get }
}
extension IVectorChangedEventArgs {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation_Collections.IVectorChangedEventArgsWrapper.IID:
let wrapper = __ABI_Windows_Foundation_Collections.IVectorChangedEventArgsWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIVectorChangedEventArgs = any IVectorChangedEventArgs
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorview-1)
public protocol IVectorView<T> : IIterable, Collection where Element == T, Index == Int {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorview-1.getat)
func getAt(_ index: UInt32) -> T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorview-1.indexof)
func indexOf(_ value: T, _ index: inout UInt32) -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivectorview-1.size)
var size: UInt32 { get }
}
public typealias AnyIVectorView<T> = any IVectorView<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1)
public protocol IVector<T> : IIterable, Collection where Element == T, Index == Int {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.getat)
func getAt(_ index: UInt32) -> T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.getview)
func getView() -> WindowsFoundation.AnyIVectorView<T>?
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.indexof)
func indexOf(_ value: T, _ index: inout UInt32) -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.setat)
func setAt(_ index: UInt32, _ value: T)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.insertat)
func insertAt(_ index: UInt32, _ value: T)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.removeat)
func removeAt(_ index: UInt32)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.append)
func append(_ value: T)
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.removeatend)
func removeAtEnd()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.clear)
func clear()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.ivector-1.size)
var size: UInt32 { get }
}
public typealias AnyIVector<T> = any IVector<T>
extension WindowsFoundation.CollectionChange {
public static var reset : WindowsFoundation.CollectionChange {
CollectionChange_Reset
}
public static var itemInserted : WindowsFoundation.CollectionChange {
CollectionChange_ItemInserted
}
public static var itemRemoved : WindowsFoundation.CollectionChange {
CollectionChange_ItemRemoved
}
public static var itemChanged : WindowsFoundation.CollectionChange {
CollectionChange_ItemChanged
}
}
extension WindowsFoundation.CollectionChange: @retroactive Hashable, @retroactive Codable {}

View File

@ -0,0 +1,48 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
public enum __ABI_Windows_Foundation_Numerics {
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CMatrix3x2 {
public static func from(swift: WindowsFoundation.Matrix3x2) -> __x_ABI_CWindows_CFoundation_CNumerics_CMatrix3x2 {
.init(M11: swift.m11, M12: swift.m12, M21: swift.m21, M22: swift.m22, M31: swift.m31, M32: swift.m32)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CMatrix4x4 {
public static func from(swift: WindowsFoundation.Matrix4x4) -> __x_ABI_CWindows_CFoundation_CNumerics_CMatrix4x4 {
.init(M11: swift.m11, M12: swift.m12, M13: swift.m13, M14: swift.m14, M21: swift.m21, M22: swift.m22, M23: swift.m23, M24: swift.m24, M31: swift.m31, M32: swift.m32, M33: swift.m33, M34: swift.m34, M41: swift.m41, M42: swift.m42, M43: swift.m43, M44: swift.m44)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CVector3 {
public static func from(swift: WindowsFoundation.Vector3) -> __x_ABI_CWindows_CFoundation_CNumerics_CVector3 {
.init(X: swift.x, Y: swift.y, Z: swift.z)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CPlane {
public static func from(swift: WindowsFoundation.Plane) -> __x_ABI_CWindows_CFoundation_CNumerics_CPlane {
.init(Normal: .from(swift: swift.normal), D: swift.d)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CQuaternion {
public static func from(swift: WindowsFoundation.Quaternion) -> __x_ABI_CWindows_CFoundation_CNumerics_CQuaternion {
.init(X: swift.x, Y: swift.y, Z: swift.z, W: swift.w)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CRational {
public static func from(swift: WindowsFoundation.Rational) -> __x_ABI_CWindows_CFoundation_CNumerics_CRational {
.init(Numerator: swift.numerator, Denominator: swift.denominator)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CVector2 {
public static func from(swift: WindowsFoundation.Vector2) -> __x_ABI_CWindows_CFoundation_CNumerics_CVector2 {
.init(X: swift.x, Y: swift.y)
}
}
extension __x_ABI_CWindows_CFoundation_CNumerics_CVector4 {
public static func from(swift: WindowsFoundation.Vector4) -> __x_ABI_CWindows_CFoundation_CNumerics_CVector4 {
.init(X: swift.x, Y: swift.y, Z: swift.z, W: swift.w)
}
}

View File

@ -0,0 +1,7 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
public enum __IMPL_Windows_Foundation_Numerics {
}

View File

@ -0,0 +1,202 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2)
public struct Matrix3x2: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m11)
public var m11: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m12)
public var m12: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m21)
public var m21: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m22)
public var m22: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m31)
public var m31: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix3x2.m32)
public var m32: Float = 0.0
public init() {}
public init(m11: Float, m12: Float, m21: Float, m22: Float, m31: Float, m32: Float) {
self.m11 = m11
self.m12 = m12
self.m21 = m21
self.m22 = m22
self.m31 = m31
self.m32 = m32
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CMatrix3x2) -> Matrix3x2 {
.init(m11: abi.M11, m12: abi.M12, m21: abi.M21, m22: abi.M22, m31: abi.M31, m32: abi.M32)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4)
public struct Matrix4x4: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m11)
public var m11: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m12)
public var m12: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m13)
public var m13: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m14)
public var m14: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m21)
public var m21: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m22)
public var m22: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m23)
public var m23: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m24)
public var m24: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m31)
public var m31: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m32)
public var m32: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m33)
public var m33: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m34)
public var m34: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m41)
public var m41: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m42)
public var m42: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m43)
public var m43: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.matrix4x4.m44)
public var m44: Float = 0.0
public init() {}
public init(m11: Float, m12: Float, m13: Float, m14: Float, m21: Float, m22: Float, m23: Float, m24: Float, m31: Float, m32: Float, m33: Float, m34: Float, m41: Float, m42: Float, m43: Float, m44: Float) {
self.m11 = m11
self.m12 = m12
self.m13 = m13
self.m14 = m14
self.m21 = m21
self.m22 = m22
self.m23 = m23
self.m24 = m24
self.m31 = m31
self.m32 = m32
self.m33 = m33
self.m34 = m34
self.m41 = m41
self.m42 = m42
self.m43 = m43
self.m44 = m44
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CMatrix4x4) -> Matrix4x4 {
.init(m11: abi.M11, m12: abi.M12, m13: abi.M13, m14: abi.M14, m21: abi.M21, m22: abi.M22, m23: abi.M23, m24: abi.M24, m31: abi.M31, m32: abi.M32, m33: abi.M33, m34: abi.M34, m41: abi.M41, m42: abi.M42, m43: abi.M43, m44: abi.M44)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector3)
public struct Vector3: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector3.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector3.y)
public var y: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector3.z)
public var z: Float = 0.0
public init() {}
public init(x: Float, y: Float, z: Float) {
self.x = x
self.y = y
self.z = z
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CVector3) -> Vector3 {
.init(x: abi.X, y: abi.Y, z: abi.Z)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.plane)
public struct Plane: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.plane.normal)
public var normal: Vector3 = .init()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.plane.d)
public var d: Float = 0.0
public init() {}
public init(normal: Vector3, d: Float) {
self.normal = normal
self.d = d
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CPlane) -> Plane {
.init(normal: .from(abi: abi.Normal), d: abi.D)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.quaternion)
public struct Quaternion: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.quaternion.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.quaternion.y)
public var y: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.quaternion.z)
public var z: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.quaternion.w)
public var w: Float = 0.0
public init() {}
public init(x: Float, y: Float, z: Float, w: Float) {
self.x = x
self.y = y
self.z = z
self.w = w
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CQuaternion) -> Quaternion {
.init(x: abi.X, y: abi.Y, z: abi.Z, w: abi.W)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.rational)
public struct Rational: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.rational.numerator)
public var numerator: UInt32 = 0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.rational.denominator)
public var denominator: UInt32 = 0
public init() {}
public init(numerator: UInt32, denominator: UInt32) {
self.numerator = numerator
self.denominator = denominator
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CRational) -> Rational {
.init(numerator: abi.Numerator, denominator: abi.Denominator)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector2)
public struct Vector2: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector2.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector2.y)
public var y: Float = 0.0
public init() {}
public init(x: Float, y: Float) {
self.x = x
self.y = y
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CVector2) -> Vector2 {
.init(x: abi.X, y: abi.Y)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector4)
public struct Vector4: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector4.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector4.y)
public var y: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector4.z)
public var z: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.numerics.vector4.w)
public var w: Float = 0.0
public init() {}
public init(x: Float, y: Float, z: Float, w: Float) {
self.x = x
self.y = y
self.z = z
self.w = w
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CNumerics_CVector4) -> Vector4 {
.init(x: abi.X, y: abi.Y, z: abi.Z, w: abi.W)
}
}

View File

@ -0,0 +1,956 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.asyncstatus)
public typealias AsyncStatus = __x_ABI_CWindows_CFoundation_CAsyncStatus
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.propertytype)
public typealias PropertyType = __x_ABI_CWindows_CFoundation_CPropertyType
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.deferral)
public final class Deferral : WinRTClass, IClosable {
private typealias SwiftABI = __ABI_Windows_Foundation.IDeferral
private typealias CABI = __x_ABI_CWindows_CFoundation_CIDeferral
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CIDeferral>?) -> Deferral? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
private static let _IDeferralFactory: __ABI_Windows_Foundation.IDeferralFactory = try! RoGetActivationFactory(HString("Windows.Foundation.Deferral"))
public init(_ handler: DeferralCompletedHandler!) {
super.init(try! Self._IDeferralFactory.CreateImpl(handler))
}
private lazy var _IClosable: __ABI_Windows_Foundation.IClosable! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.deferral.close)
public func close() throws {
try _IClosable.CloseImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.deferral.complete)
public func complete() throws {
try _default.CompleteImpl()
}
deinit {
_IClosable = nil
_default = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.guidhelper)
public final class GuidHelper {
private static let _IGuidHelperStatics: __ABI_Windows_Foundation.IGuidHelperStatics = try! RoGetActivationFactory(HString("Windows.Foundation.GuidHelper"))
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.guidhelper.createnewguid)
public static func createNewGuid() -> Foundation.UUID {
return try! _IGuidHelperStatics.CreateNewGuidImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.guidhelper.empty)
public static var empty : Foundation.UUID {
get { try! _IGuidHelperStatics.get_EmptyImpl() }
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.memorybuffer)
public final class MemoryBuffer : WinRTClass, IClosable, IMemoryBuffer {
private typealias SwiftABI = __ABI_Windows_Foundation.IMemoryBuffer
private typealias CABI = __x_ABI_CWindows_CFoundation_CIMemoryBuffer
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CIMemoryBuffer>?) -> MemoryBuffer? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
private static let _IMemoryBufferFactory: __ABI_Windows_Foundation.IMemoryBufferFactory = try! RoGetActivationFactory(HString("Windows.Foundation.MemoryBuffer"))
public init(_ capacity: UInt32) {
super.init(try! Self._IMemoryBufferFactory.CreateImpl(capacity))
}
private lazy var _IClosable: __ABI_Windows_Foundation.IClosable! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.memorybuffer.close)
public func close() throws {
try _IClosable.CloseImpl()
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.memorybuffer.createreference)
public func createReference() throws -> AnyIMemoryBufferReference! {
try _default.CreateReferenceImpl()
}
deinit {
_IClosable = nil
_default = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri)
public final class Uri : WinRTClass, IStringable {
private typealias SwiftABI = __ABI_Windows_Foundation.IUriRuntimeClass
private typealias CABI = __x_ABI_CWindows_CFoundation_CIUriRuntimeClass
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CIUriRuntimeClass>?) -> Uri? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
private static let _IUriEscapeStatics: __ABI_Windows_Foundation.IUriEscapeStatics = try! RoGetActivationFactory(HString("Windows.Foundation.Uri"))
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.unescapecomponent)
public static func unescapeComponent(_ toUnescape: String) -> String {
return try! _IUriEscapeStatics.UnescapeComponentImpl(toUnescape)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.escapecomponent)
public static func escapeComponent(_ toEscape: String) -> String {
return try! _IUriEscapeStatics.EscapeComponentImpl(toEscape)
}
private static let _IUriRuntimeClassFactory: __ABI_Windows_Foundation.IUriRuntimeClassFactory = try! RoGetActivationFactory(HString("Windows.Foundation.Uri"))
public init(_ uri: String) {
super.init(try! Self._IUriRuntimeClassFactory.CreateUriImpl(uri))
}
public init(_ baseUri: String, _ relativeUri: String) {
super.init(try! Self._IUriRuntimeClassFactory.CreateWithRelativeUriImpl(baseUri, relativeUri))
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.equals)
public func equals(_ pUri: Uri!) throws -> Bool {
try _default.EqualsImpl(pUri)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.combineuri)
public func combineUri(_ relativeUri: String) throws -> Uri! {
try _default.CombineUriImpl(relativeUri)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.absoluteuri)
public var absoluteUri : String {
get { try! _default.get_AbsoluteUriImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.displayuri)
public var displayUri : String {
get { try! _default.get_DisplayUriImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.domain)
public var domain : String {
get { try! _default.get_DomainImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.extension)
public var `extension` : String {
get { try! _default.get_ExtensionImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.fragment)
public var fragment : String {
get { try! _default.get_FragmentImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.host)
public var host : String {
get { try! _default.get_HostImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.password)
public var password : String {
get { try! _default.get_PasswordImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.path)
public var path : String {
get { try! _default.get_PathImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.port)
public var port : Int32 {
get { try! _default.get_PortImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.query)
public var query : String {
get { try! _default.get_QueryImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.queryparsed)
public var queryParsed : WwwFormUrlDecoder! {
get { try! _default.get_QueryParsedImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.rawuri)
public var rawUri : String {
get { try! _default.get_RawUriImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.schemename)
public var schemeName : String {
get { try! _default.get_SchemeNameImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.suspicious)
public var suspicious : Bool {
get { try! _default.get_SuspiciousImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.username)
public var userName : String {
get { try! _default.get_UserNameImpl() }
}
private lazy var _IUriRuntimeClassWithAbsoluteCanonicalUri: __ABI_Windows_Foundation.IUriRuntimeClassWithAbsoluteCanonicalUri! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.absolutecanonicaluri)
public var absoluteCanonicalUri : String {
get { try! _IUriRuntimeClassWithAbsoluteCanonicalUri.get_AbsoluteCanonicalUriImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.displayiri)
public var displayIri : String {
get { try! _IUriRuntimeClassWithAbsoluteCanonicalUri.get_DisplayIriImpl() }
}
private lazy var _IStringable: __ABI_Windows_Foundation.IStringable! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.uri.tostring)
public func toString() throws -> String {
try _IStringable.ToStringImpl()
}
deinit {
_default = nil
_IUriRuntimeClassWithAbsoluteCanonicalUri = nil
_IStringable = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder)
public final class WwwFormUrlDecoder : WinRTClass, IIterable, IVectorView {
public typealias T = AnyIWwwFormUrlDecoderEntry?
private typealias SwiftABI = __ABI_Windows_Foundation.IWwwFormUrlDecoderRuntimeClass
private typealias CABI = __x_ABI_CWindows_CFoundation_CIWwwFormUrlDecoderRuntimeClass
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CIWwwFormUrlDecoderRuntimeClass>?) -> WwwFormUrlDecoder? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
private static let _IWwwFormUrlDecoderRuntimeClassFactory: __ABI_Windows_Foundation.IWwwFormUrlDecoderRuntimeClassFactory = try! RoGetActivationFactory(HString("Windows.Foundation.WwwFormUrlDecoder"))
public init(_ query: String) {
super.init(try! Self._IWwwFormUrlDecoderRuntimeClassFactory.CreateWwwFormUrlDecoderImpl(query))
}
private lazy var _IIterable: IIterableIWwwFormUrlDecoderEntry! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder.first)
public func first() -> AnyIIterator<AnyIWwwFormUrlDecoderEntry?>? {
try! _IIterable.FirstImpl()
}
// MARK: Collection
public typealias Element = T
public var startIndex: Int { 0 }
public var endIndex: Int { Int(size) }
public func index(after i: Int) -> Int {
i+1
}
public func index(of: Element) -> Int? {
var index: UInt32 = 0
let result = indexOf(of, &index)
guard result else { return nil }
return Int(index)
}
public var count: Int { Int(size) }
public subscript(position: Int) -> Element {
get {
getAt(UInt32(position))
}
}
// MARK: WinRT
private lazy var _IVectorView: IVectorViewIWwwFormUrlDecoderEntry! = getInterfaceForCaching()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder.getat)
public func getAt(_ index: UInt32) -> AnyIWwwFormUrlDecoderEntry? {
try! _IVectorView.GetAtImpl(index)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder.indexof)
public func indexOf(_ value: AnyIWwwFormUrlDecoderEntry?, _ index: inout UInt32) -> Bool {
try! _IVectorView.IndexOfImpl(value, &index)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder.size)
public var size : UInt32 {
get { try! _IVectorView.get_SizeImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoder.getfirstvaluebyname)
public func getFirstValueByName(_ name: String) throws -> String {
try _default.GetFirstValueByNameImpl(name)
}
deinit {
_IIterable = nil
_IVectorView = nil
_default = nil
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoderentry)
public final class WwwFormUrlDecoderEntry : WinRTClass, IWwwFormUrlDecoderEntry {
private typealias SwiftABI = __ABI_Windows_Foundation.IWwwFormUrlDecoderEntry
private typealias CABI = __x_ABI_CWindows_CFoundation_CIWwwFormUrlDecoderEntry
private lazy var _default: SwiftABI! = getInterfaceForCaching()
@_spi(WinRTInternal)
override public func _getABI<T>() -> UnsafeMutablePointer<T>? {
if T.self == CABI.self {
return RawPointer(_default)
}
return super._getABI()
}
@_spi(WinRTInternal)
public static func from(abi: ComPtr<__x_ABI_CWindows_CFoundation_CIWwwFormUrlDecoderEntry>?) -> WwwFormUrlDecoderEntry? {
guard let abi = abi else { return nil }
return .init(fromAbi: WindowsFoundation.IInspectable(abi))
}
@_spi(WinRTInternal)
public init(fromAbi: WindowsFoundation.IInspectable) {
super.init(fromAbi)
}
override public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
return super.queryInterface(iid)
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoderentry.name)
public var name : String {
get { try! _default.get_NameImpl() }
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.wwwformurldecoderentry.value)
public var value : String {
get { try! _default.get_ValueImpl() }
}
deinit {
_default = nil
}
}
public typealias AsyncActionCompletedHandler = (AnyIAsyncAction?, AsyncStatus) -> ()
public typealias AsyncActionProgressHandler<TProgress> = (AnyIAsyncActionWithProgress<TProgress>?, TProgress) -> ()
public typealias AsyncActionWithProgressCompletedHandler<TProgress> = (AnyIAsyncActionWithProgress<TProgress>?, AsyncStatus) -> ()
public typealias AsyncOperationCompletedHandler<TResult> = (AnyIAsyncOperation<TResult>?, AsyncStatus) -> ()
public typealias AsyncOperationProgressHandler<TResult,TProgress> = (AnyIAsyncOperationWithProgress<TResult, TProgress>?, TProgress) -> ()
public typealias AsyncOperationWithProgressCompletedHandler<TResult,TProgress> = (AnyIAsyncOperationWithProgress<TResult, TProgress>?, AsyncStatus) -> ()
public typealias DeferralCompletedHandler = () -> ()
public typealias EventHandler<T> = (Any?, T) -> ()
public typealias TypedEventHandler<TSender,TResult> = (TSender, TResult) -> ()
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.datetime)
public struct DateTime: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.datetime.universaltime)
public var universalTime: Int64 = 0
public init() {}
public init(universalTime: Int64) {
self.universalTime = universalTime
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CDateTime) -> DateTime {
.init(universalTime: abi.UniversalTime)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.point)
public struct Point: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.point.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.point.y)
public var y: Float = 0.0
public init() {}
public init(x: Float, y: Float) {
self.x = x
self.y = y
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CPoint) -> Point {
.init(x: abi.X, y: abi.Y)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.rect)
public struct Rect: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.rect.x)
public var x: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.rect.y)
public var y: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.rect.width)
public var width: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.rect.height)
public var height: Float = 0.0
public init() {}
public init(x: Float, y: Float, width: Float, height: Float) {
self.x = x
self.y = y
self.width = width
self.height = height
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CRect) -> Rect {
.init(x: abi.X, y: abi.Y, width: abi.Width, height: abi.Height)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.size)
public struct Size: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.size.width)
public var width: Float = 0.0
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.size.height)
public var height: Float = 0.0
public init() {}
public init(width: Float, height: Float) {
self.width = width
self.height = height
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CSize) -> Size {
.init(width: abi.Width, height: abi.Height)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.timespan)
public struct TimeSpan: Hashable, Codable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.timespan.duration)
public var duration: Int64 = 0
public init() {}
public init(duration: Int64) {
self.duration = duration
}
public static func from(abi: __x_ABI_CWindows_CFoundation_CTimeSpan) -> TimeSpan {
.init(duration: abi.Duration)
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction)
public protocol IAsyncAction : IAsyncInfo {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.getresults)
func getResults() throws
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncaction.completed)
var completed: WindowsFoundation.AsyncActionCompletedHandler! { get set }
}
extension IAsyncAction {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IAsyncActionWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IAsyncActionWrapper(self)
return wrapper!.queryInterface(iid)
case __ABI_Windows_Foundation.IAsyncInfoWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IAsyncInfoWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIAsyncAction = any IAsyncAction
public extension IAsyncAction {
func get() async throws {
if status == .started {
let event = WaitableEvent()
completed = { _, _ in
Task { await event.signal() }
}
await event.wait()
}
return try getResults()
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncactionwithprogress-1)
public protocol IAsyncActionWithProgress<TProgress> : IAsyncInfo {
associatedtype TProgress
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncactionwithprogress-1.getresults)
func getResults() throws
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncactionwithprogress-1.progress)
var progress: WindowsFoundation.AsyncActionProgressHandler<TProgress>? { get set }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncactionwithprogress-1.completed)
var completed: WindowsFoundation.AsyncActionWithProgressCompletedHandler<TProgress>? { get set }
}
public typealias AnyIAsyncActionWithProgress<TProgress> = any IAsyncActionWithProgress<TProgress>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo)
public protocol IAsyncInfo : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.cancel)
func cancel() throws
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.close)
func close() throws
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.errorcode)
var errorCode: HRESULT { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.id)
var id: UInt32 { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncinfo.status)
var status: WindowsFoundation.AsyncStatus { get }
}
extension IAsyncInfo {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IAsyncInfoWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IAsyncInfoWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIAsyncInfo = any IAsyncInfo
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperationwithprogress-2)
public protocol IAsyncOperationWithProgress<TResult,TProgress> : IAsyncInfo {
associatedtype TResult
associatedtype TProgress
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperationwithprogress-2.getresults)
func getResults() throws -> TResult
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperationwithprogress-2.progress)
var progress: WindowsFoundation.AsyncOperationProgressHandler<TResult, TProgress>? { get set }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperationwithprogress-2.completed)
var completed: WindowsFoundation.AsyncOperationWithProgressCompletedHandler<TResult, TProgress>? { get set }
}
public typealias AnyIAsyncOperationWithProgress<TResult,TProgress> = any IAsyncOperationWithProgress<TResult,TProgress>
public extension IAsyncOperationWithProgress {
func get() async throws -> TResult {
if status == .started {
let event = WaitableEvent()
completed = { _, _ in
Task { await event.signal() }
}
await event.wait()
}
return try getResults()
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperation-1)
public protocol IAsyncOperation<TResult> : IAsyncInfo {
associatedtype TResult
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperation-1.getresults)
func getResults() throws -> TResult
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iasyncoperation-1.completed)
var completed: WindowsFoundation.AsyncOperationCompletedHandler<TResult>? { get set }
}
public typealias AnyIAsyncOperation<TResult> = any IAsyncOperation<TResult>
public extension IAsyncOperation {
func get() async throws -> TResult {
if status == .started {
let event = WaitableEvent()
completed = { _, _ in
Task { await event.signal() }
}
await event.wait()
}
return try getResults()
}
}
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iclosable)
public protocol IClosable : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iclosable.close)
func close() throws
}
extension IClosable {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IClosableWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IClosableWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIClosable = any IClosable
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.igetactivationfactory)
public protocol IGetActivationFactory : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.igetactivationfactory.getactivationfactory)
func getActivationFactory(_ activatableClassId: String) throws -> Any!
}
extension IGetActivationFactory {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IGetActivationFactoryWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IGetActivationFactoryWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIGetActivationFactory = any IGetActivationFactory
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybuffer)
public protocol IMemoryBuffer : IClosable {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybuffer.createreference)
func createReference() throws -> WindowsFoundation.AnyIMemoryBufferReference!
}
extension IMemoryBuffer {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IMemoryBufferWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IMemoryBufferWrapper(self)
return wrapper!.queryInterface(iid)
case __ABI_Windows_Foundation.IClosableWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IClosableWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIMemoryBuffer = any IMemoryBuffer
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference)
public protocol IMemoryBufferReference : IClosable, IMemoryBufferByteAccess {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference.capacity)
var capacity: UInt32 { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.imemorybufferreference.closed)
var closed: Event<TypedEventHandler<IMemoryBufferReference?, Any?>> { get }
}
extension IMemoryBufferReference {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IMemoryBufferReferenceWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IMemoryBufferReferenceWrapper(self)
return wrapper!.queryInterface(iid)
case __ABI_Windows_Foundation.IClosableWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IClosableWrapper(self)
return wrapper!.queryInterface(iid)
case __ABI_.IMemoryBufferByteAccessWrapper.IID:
let wrapper = __ABI_.IMemoryBufferByteAccessWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
extension IMemoryBufferReference {
public var data: Data {
guard let buffer = try? buffer, let ptr = buffer.baseAddress else { return Data() }
return Data(bytesNoCopy: ptr, count: buffer.count, deallocator: .none)
}
}
public typealias AnyIMemoryBufferReference = any IMemoryBufferReference
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue)
public protocol IPropertyValue : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getuint8)
func getUInt8() throws -> UInt8
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getint16)
func getInt16() throws -> Int16
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getuint16)
func getUInt16() throws -> UInt16
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getint32)
func getInt32() throws -> Int32
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getuint32)
func getUInt32() throws -> UInt32
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getint64)
func getInt64() throws -> Int64
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getuint64)
func getUInt64() throws -> UInt64
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getsingle)
func getSingle() throws -> Float
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getdouble)
func getDouble() throws -> Double
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getchar16)
func getChar16() throws -> Character
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getboolean)
func getBoolean() throws -> Bool
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getstring)
func getString() throws -> String
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getguid)
func getGuid() throws -> Foundation.UUID
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getdatetime)
func getDateTime() throws -> WindowsFoundation.DateTime
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.gettimespan)
func getTimeSpan() throws -> WindowsFoundation.TimeSpan
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getpoint)
func getPoint() throws -> WindowsFoundation.Point
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getsize)
func getSize() throws -> WindowsFoundation.Size
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.getrect)
func getRect() throws -> WindowsFoundation.Rect
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.isnumericscalar)
var isNumericScalar: Bool { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ipropertyvalue.type)
var type: WindowsFoundation.PropertyType { get }
}
public typealias AnyIPropertyValue = any IPropertyValue
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ireferencearray-1)
public protocol IReferenceArray<T> : IPropertyValue {
associatedtype T
}
public typealias AnyIReferenceArray<T> = any IReferenceArray<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ireference-1)
public protocol IReference<T> : IPropertyValue {
associatedtype T
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.ireference-1.value)
var value: T { get }
}
public typealias AnyIReference<T> = any IReference<T>
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.istringable)
public protocol IStringable : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.istringable.tostring)
func toString() throws -> String
}
extension IStringable {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IStringableWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IStringableWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIStringable = any IStringable
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iwwwformurldecoderentry)
public protocol IWwwFormUrlDecoderEntry : WinRTInterface {
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iwwwformurldecoderentry.name)
var name: String { get }
/// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.iwwwformurldecoderentry.value)
var value: String { get }
}
extension IWwwFormUrlDecoderEntry {
public func queryInterface(_ iid: WindowsFoundation.IID) -> IUnknownRef? {
switch iid {
case __ABI_Windows_Foundation.IWwwFormUrlDecoderEntryWrapper.IID:
let wrapper = __ABI_Windows_Foundation.IWwwFormUrlDecoderEntryWrapper(self)
return wrapper!.queryInterface(iid)
default: return nil
}
}
}
public typealias AnyIWwwFormUrlDecoderEntry = any IWwwFormUrlDecoderEntry
extension WindowsFoundation.AsyncStatus {
public static var canceled : WindowsFoundation.AsyncStatus {
__x_ABI_CWindows_CFoundation_CAsyncStatus_Canceled
}
public static var completed : WindowsFoundation.AsyncStatus {
__x_ABI_CWindows_CFoundation_CAsyncStatus_Completed
}
public static var error : WindowsFoundation.AsyncStatus {
__x_ABI_CWindows_CFoundation_CAsyncStatus_Error
}
public static var started : WindowsFoundation.AsyncStatus {
__x_ABI_CWindows_CFoundation_CAsyncStatus_Started
}
}
extension WindowsFoundation.AsyncStatus: @retroactive Hashable, @retroactive Codable {}
extension WindowsFoundation.PropertyType {
public static var empty : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Empty
}
public static var uint8 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt8
}
public static var int16 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int16
}
public static var uint16 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt16
}
public static var int32 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int32
}
public static var uint32 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt32
}
public static var int64 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int64
}
public static var uint64 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt64
}
public static var single : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Single
}
public static var double : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Double
}
public static var char16 : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Char16
}
public static var boolean : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Boolean
}
public static var string : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_String
}
public static var inspectable : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Inspectable
}
public static var dateTime : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_DateTime
}
public static var timeSpan : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_TimeSpan
}
public static var guid : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Guid
}
public static var point : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Point
}
public static var size : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Size
}
public static var rect : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Rect
}
public static var otherType : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_OtherType
}
public static var uint8Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt8Array
}
public static var int16Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int16Array
}
public static var uint16Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt16Array
}
public static var int32Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int32Array
}
public static var uint32Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt32Array
}
public static var int64Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Int64Array
}
public static var uint64Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_UInt64Array
}
public static var singleArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_SingleArray
}
public static var doubleArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_DoubleArray
}
public static var char16Array : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_Char16Array
}
public static var booleanArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_BooleanArray
}
public static var stringArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_StringArray
}
public static var inspectableArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_InspectableArray
}
public static var dateTimeArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_DateTimeArray
}
public static var timeSpanArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_TimeSpanArray
}
public static var guidArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_GuidArray
}
public static var pointArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_PointArray
}
public static var sizeArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_SizeArray
}
public static var rectArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_RectArray
}
public static var otherTypeArray : WindowsFoundation.PropertyType {
__x_ABI_CWindows_CFoundation_CPropertyType_OtherTypeArray
}
}
extension WindowsFoundation.PropertyType: @retroactive Hashable, @retroactive Codable {}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,113 @@
// WARNING: Please don't edit this file. It was generated by Swift/WinRT v0.0.1
// swiftlint:disable all
import Foundation
import CWinRT
fileprivate func makeIAsyncActionFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IAsyncAction = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IAsyncActionBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIAsyncInfoFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IAsyncInfo = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IAsyncInfoBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIClosableFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IClosable = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IClosableBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIGetActivationFactoryFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IGetActivationFactory = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IGetActivationFactoryBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIMemoryBufferFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IMemoryBuffer = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IMemoryBufferBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIMemoryBufferReferenceFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IMemoryBufferReference = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IMemoryBufferReferenceBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIStringableFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IStringable = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IStringableBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIWwwFormUrlDecoderEntryFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation.IWwwFormUrlDecoderEntry = try! abi.QueryInterface()
return __IMPL_Windows_Foundation.IWwwFormUrlDecoderEntryBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIPropertySetFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation_Collections.IPropertySet = try! abi.QueryInterface()
return __IMPL_Windows_Foundation_Collections.IPropertySetBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeIVectorChangedEventArgsFrom(abi: WindowsFoundation.IInspectable) -> Any {
let swiftAbi: __ABI_Windows_Foundation_Collections.IVectorChangedEventArgs = try! abi.QueryInterface()
return __IMPL_Windows_Foundation_Collections.IVectorChangedEventArgsBridge.from(abi: RawPointer(swiftAbi))!
}
fileprivate func makeDeferralFrom(abi: WindowsFoundation.IInspectable) -> Any {
return Deferral(fromAbi: abi)
}
fileprivate func makeMemoryBufferFrom(abi: WindowsFoundation.IInspectable) -> Any {
return MemoryBuffer(fromAbi: abi)
}
fileprivate func makeUriFrom(abi: WindowsFoundation.IInspectable) -> Any {
return Uri(fromAbi: abi)
}
fileprivate func makeWwwFormUrlDecoderFrom(abi: WindowsFoundation.IInspectable) -> Any {
return WwwFormUrlDecoder(fromAbi: abi)
}
fileprivate func makeWwwFormUrlDecoderEntryFrom(abi: WindowsFoundation.IInspectable) -> Any {
return WwwFormUrlDecoderEntry(fromAbi: abi)
}
fileprivate func makePropertySetFrom(abi: WindowsFoundation.IInspectable) -> Any {
return PropertySet(fromAbi: abi)
}
fileprivate func makeStringMapFrom(abi: WindowsFoundation.IInspectable) -> Any {
return StringMap(fromAbi: abi)
}
fileprivate func makeValueSetFrom(abi: WindowsFoundation.IInspectable) -> Any {
return ValueSet(fromAbi: abi)
}
@_spi(__MakeFromAbi_DoNotImport)
public class __MakeFromAbi: MakeFromAbi {
public static func from(typeName: String, abi: WindowsFoundation.IInspectable) -> Any? {
switch typeName {
case "IAsyncAction": return makeIAsyncActionFrom(abi: abi)
case "IAsyncInfo": return makeIAsyncInfoFrom(abi: abi)
case "IClosable": return makeIClosableFrom(abi: abi)
case "IGetActivationFactory": return makeIGetActivationFactoryFrom(abi: abi)
case "IMemoryBuffer": return makeIMemoryBufferFrom(abi: abi)
case "IMemoryBufferReference": return makeIMemoryBufferReferenceFrom(abi: abi)
case "IStringable": return makeIStringableFrom(abi: abi)
case "IWwwFormUrlDecoderEntry": return makeIWwwFormUrlDecoderEntryFrom(abi: abi)
case "IPropertySet": return makeIPropertySetFrom(abi: abi)
case "IVectorChangedEventArgs": return makeIVectorChangedEventArgsFrom(abi: abi)
case "Deferral": return makeDeferralFrom(abi: abi)
case "MemoryBuffer": return makeMemoryBufferFrom(abi: abi)
case "Uri": return makeUriFrom(abi: abi)
case "WwwFormUrlDecoder": return makeWwwFormUrlDecoderFrom(abi: abi)
case "WwwFormUrlDecoderEntry": return makeWwwFormUrlDecoderEntryFrom(abi: abi)
case "PropertySet": return makePropertySetFrom(abi: abi)
case "StringMap": return makeStringMapFrom(abi: abi)
case "ValueSet": return makeValueSetFrom(abi: abi)
default: return nil
}
}
}

138
generate-bindings.ps1 Normal file
View File

@ -0,0 +1,138 @@
function Get-SwiftWinRTVersion {
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
return $Projections."swift-winrt"
}
function Get-PackageString {
param(
$Package
)
if ($Package) {
return " <package id=""$($Package.Id)"" version=""$($Package.Version)"" />`n"
}
}
function Restore-Nuget {
param(
[string]$PackagesDir
)
$NugetDownloadPath = Join-Path $env:TEMP "nuget.exe"
if (-not (Test-Path $NugetDownloadPath)) {
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $NugetDownloadPath
}
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
$SwiftWinRTVersion = Get-SwiftWinRTVersion
$PackagesConfigContent = "<?xml version=""1.0"" encoding=""utf-8""?>`n"
$PackagesConfigContent += "<packages>`n"
$PackagesConfigContent += " <package id=""TheBrowserCompany.SwiftWinRT"" version=""$SwiftWinRTVersion"" />`n"
if ($Projections.Package) {
$PackagesConfigContent += Get-PackageString -Package $Projections.Package
}
$Projections.Packages | ForEach-Object {
$PackagesConfigContent += Get-PackageString -Package $_
}
$Projections.Dependencies | ForEach-Object {
$PackagesConfigContent += Get-PackageString -Package $_
}
$PackagesConfigContent += "</packages>"
if (-not (Test-Path "$PSScriptRoot\.packages")) {
New-Item -ItemType Directory -Path "$PSScriptRoot\.packages" | Out-Null
}
$PackagesConfigPath = Join-Path $PSScriptRoot ".packages\packages.config"
$PackagesConfigContent | Out-File -FilePath $PackagesConfigPath
& $NugetDownloadPath restore $PackagesConfigPath -PackagesDirectory $PackagesDir | Out-Null
if ($LASTEXITCODE -ne 0) {
exit 1
}
}
function Get-WinMDInputs() {
param(
$Package
)
$Id = $Package.Id
$Version = $Package.Version
return Get-ChildItem -Path $PackagesDir\$Id.$Version\ -Filter *.winmd -Recurse
}
function Copy-Project {
param(
[string]$OutputLocation,
[string]$ProjectName
)
if ($ProjectName) {
$ProjectGeneratedDir = if ($ProjectName -eq "CWinRT") { "$ProjectName" } else { "$ProjectName\Generated" }
$ProjectDir = Join-Path $PSScriptRoot "Sources\$ProjectGeneratedDir"
if (Test-Path $ProjectDir) {
Remove-Item -Path $ProjectDir -Recurse -Force
}
Copy-Item -Path $OutputLocation\Sources\$ProjectName -Destination $ProjectDir -Recurse -Force
}
}
function Invoke-SwiftWinRT() {
param(
[string]$PackagesDir
)
$Projections = Get-Content -Path $PSScriptRoot\projections.json | ConvertFrom-Json
$SwiftWinRTVersion = Get-SwiftWinRTVersion
# write generated bindings to a temp directory since swiftwinrt will generate all dependencies and the CWinRT
$OutputLocation = Join-Path $PSScriptRoot ".generated"
if (Test-Path $OutputLocation) {
Remove-Item -Path $OutputLocation -Recurse -Force
}
$RspParams = "-output $OutputLocation`n"
# read projections.json and for each "include" write to -include param. for each "exclude" write to -exclude param
$Projections.Include | ForEach-Object {
$RspParams += "-include $_`n"
}
$Projections.Exclude | ForEach-Object {
$RspParams += "-exclude $_`n"
}
if ($Projections.Package) {
Get-WinMDInputs -Package $Package | ForEach-Object {
$RspParams += "-input $($_.FullName)`n"
}
}
$Projections.Packages | ForEach-Object {
Get-WinMDInputs -Package $Package | ForEach-Object {
$RspParams += "-input $($_.FullName)`n"
}
}
$Projections.Dependencies | ForEach-Object {
Get-WinMDInputs -Package $Package | ForEach-Object {
$RspParams += "-input $($_.FullName)`n"
}
}
# write rsp params to file
$RspFile = Join-Path $PSScriptRoot "swift-winrt.rsp"
$RspParams | Out-File -FilePath $RspFile
& $PackagesDir\TheBrowserCompany.SwiftWinRT.$SwiftWinRTVersion\bin\swiftwinrt.exe "@$RspFile"
if ($LASTEXITCODE -ne 0) {
Write-Host "swiftwinrt failed with error code $LASTEXITCODE" -ForegroundColor Red
exit 1
}
$Projections.Projects | ForEach-Object {
Copy-Project -OutputLocation $OutputLocation -ProjectName $_
}
if ($Projections.Project) {
Copy-Project -OutputLocation $OutputLocation -ProjectName $Projections.Project
}
}
$PackagesDir = Join-Path $PSScriptRoot ".packages"
Restore-Nuget -PackagesDir $PackagesDir
Invoke-SwiftWinRT -PackagesDir $PackagesDir
Write-Host "SwiftWinRT bindings generated successfully!" -ForegroundColor Green

18
projections.json Normal file
View File

@ -0,0 +1,18 @@
{
"swift-winrt": "0.5.0",
"package": {
"id": "Microsoft.Windows.SDK.Contracts",
"version": "10.0.18362.2005"
},
"projects": ["WindowsFoundation"],
"dependencies": [
],
"include": [
"Windows.Foundation.Collections",
"Windows.Foundation.Numerics",
"Windows.Foundation",
],
"exclude": [
"Windows.Foundation.PropertyValue"
]
}