diff --git a/swiftwinrt/Resources/CWinRT/CppInteropWorkaround.h b/swiftwinrt/Resources/CWinRT/CppInteropWorkaround.h index b1559fbe..1d4c876c 100644 --- a/swiftwinrt/Resources/CWinRT/CppInteropWorkaround.h +++ b/swiftwinrt/Resources/CWinRT/CppInteropWorkaround.h @@ -15,6 +15,7 @@ typedef GUID_Workaround UUID_Workaround; // Functions depending on workaround types typedef struct IUnknown_Workaround IUnknown_Workaround; typedef struct IInspectable_Workaround IInspectable_Workaround; +typedef struct IActivationFactory_Workaround IActivationFactory_Workaround; typedef struct IMarshal_Workaround IMarshal_Workaround; #include @@ -66,6 +67,12 @@ inline HRESULT RoGetActivationFactory_Workaround( #endif } +// Since we can't define statically allocated arrays in swift, just use a large enough buffer to hold the data. +// In reality this could probably be closer to 128 +struct StaticWCharArray_512 { + WCHAR Data[512]; +}; + //------------------------------------------------------------------------------------------------- // Begin the great lie // Everything below will unknowingly use Xxx_Workaround. @@ -91,6 +98,8 @@ inline HRESULT RoGetActivationFactory_Workaround( #define IInspectableVtbl IInspectableVtbl_Workaround #define IMarshal IMarshal_Workaround #define IMarshalVtbl IMarshalVtbl_Workaround +#define IActivationFactory IActivationFactory_Workaround +#define IActivationFactoryVtbl IActivationFactoryVtbl_Workaround // iunknown.h typedef struct IUnknownVtbl @@ -234,4 +243,52 @@ typedef struct IMarshalVtbl interface IMarshal { CONST_VTBL struct IMarshalVtbl *lpVtbl; +}; + +typedef struct IActivationFactoryVtbl +{ + BEGIN_INTERFACE + + DECLSPEC_XFGVIRT(IUnknown, QueryInterface) + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + __RPC__in IActivationFactory * This, + /* [in] */ __RPC__in REFIID riid, + /* [annotation][iid_is][out] */ + _COM_Outptr_ void **ppvObject); + + DECLSPEC_XFGVIRT(IUnknown, AddRef) + ULONG ( STDMETHODCALLTYPE *AddRef )( + __RPC__in IActivationFactory * This); + + DECLSPEC_XFGVIRT(IUnknown, Release) + ULONG ( STDMETHODCALLTYPE *Release )( + __RPC__in IActivationFactory * This); + + DECLSPEC_XFGVIRT(IInspectable, GetIids) + HRESULT ( STDMETHODCALLTYPE *GetIids )( + __RPC__in IActivationFactory * This, + /* [out] */ __RPC__out ULONG *iidCount, + /* [size_is][size_is][out] */ __RPC__deref_out_ecount_full_opt(*iidCount) IID **iids); + + DECLSPEC_XFGVIRT(IInspectable, GetRuntimeClassName) + HRESULT ( STDMETHODCALLTYPE *GetRuntimeClassName )( + __RPC__in IActivationFactory * This, + /* [out] */ __RPC__deref_out_opt HSTRING *className); + + DECLSPEC_XFGVIRT(IInspectable, GetTrustLevel) + HRESULT ( STDMETHODCALLTYPE *GetTrustLevel )( + __RPC__in IActivationFactory * This, + /* [out] */ __RPC__out TrustLevel *trustLevel); + + DECLSPEC_XFGVIRT(IActivationFactory, ActivateInstance) + HRESULT ( STDMETHODCALLTYPE *ActivateInstance )( + __RPC__in IActivationFactory * This, + /* [out] */ __RPC__deref_out_opt IInspectable **instance); + + END_INTERFACE +} IActivationFactoryVtbl; + +interface IActivationFactory +{ + CONST_VTBL struct IActivationFactoryVtbl *lpVtbl; }; \ No newline at end of file diff --git a/swiftwinrt/Resources/Support/CppInteropWorkaround.swift b/swiftwinrt/Resources/Support/CppInteropWorkaround.swift index 496b874a..68d37bf9 100644 --- a/swiftwinrt/Resources/Support/CppInteropWorkaround.swift +++ b/swiftwinrt/Resources/Support/CppInteropWorkaround.swift @@ -10,6 +10,8 @@ public typealias C_IInspectable = C_BINDINGS_MODULE.IInspectable_Workaround public typealias C_IInspectableVtbl = C_BINDINGS_MODULE.IInspectableVtbl_Workaround public typealias C_IMarshal = C_BINDINGS_MODULE.IMarshal_Workaround public typealias C_IMarshalVtbl = C_BINDINGS_MODULE.IMarshalVtbl_Workaround +public typealias C_IActivationFactory = C_BINDINGS_MODULE.IActivationFactory_Workaround +public typealias C_IActivationFactoryVtbl = C_BINDINGS_MODULE.IActivationFactoryVtbl_Workaround internal let CoCreateInstance = C_BINDINGS_MODULE.CoCreateInstance_Workaround internal let UuidFromStringA = C_BINDINGS_MODULE.UuidFromStringA_Workaround internal let RoActivateInstance = C_BINDINGS_MODULE.RoActivateInstance_Workaround @@ -26,6 +28,8 @@ public typealias C_IInspectable = C_BINDINGS_MODULE.IInspectable public typealias C_IInspectableVtbl = C_BINDINGS_MODULE.IInspectableVtbl public typealias C_IMarshal = C_BINDINGS_MODULE.IMarshal public typealias C_IMarshalVtbl = C_BINDINGS_MODULE.IMarshalVtbl +public typealias C_IActivationFactory = C_BINDINGS_MODULE.IActivationFactory +public typealias C_IActivationFactoryVtbl = C_BINDINGS_MODULE.IActivationFactoryVtbl internal let CoCreateInstance = C_BINDINGS_MODULE.CoCreateInstance internal let UuidFromStringA = C_BINDINGS_MODULE.UuidFromStringA internal let RoActivateInstance = C_BINDINGS_MODULE.RoActivateInstance diff --git a/swiftwinrt/Resources/Support/PropertyValue.swift b/swiftwinrt/Resources/Support/PropertyValue.swift index 255127ed..8d92f97b 100644 --- a/swiftwinrt/Resources/Support/PropertyValue.swift +++ b/swiftwinrt/Resources/Support/PropertyValue.swift @@ -5,7 +5,7 @@ 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")) + private static let _IPropertyValueStatics: IPropertyValueStatics = try! RoGetActivationFactory("Windows.Foundation.PropertyValue") public static func createUInt8(_ value: UInt8) -> SUPPORT_MODULE.IInspectable { let propertyValue = try! _IPropertyValueStatics.CreateUInt8Impl(value) diff --git a/swiftwinrt/Resources/Support/Runtime+Swift.swift b/swiftwinrt/Resources/Support/Runtime+Swift.swift index 8dc50f59..15ab2567 100644 --- a/swiftwinrt/Resources/Support/Runtime+Swift.swift +++ b/swiftwinrt/Resources/Support/Runtime+Swift.swift @@ -4,20 +4,33 @@ import WinSDK import C_BINDINGS_MODULE -public func RoGetActivationFactory(_ activatableClassId: HString) throws -> Factory { +private var IID_IActivationFactory: SUPPORT_MODULE.IID { + .init(Data1: 0x00000035, Data2: 0x0000, Data3: 0x0000, Data4: ( 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 )) // 00000035-0000-0000-C000-000000000046 +} + +public class IActivationFactory: SUPPORT_MODULE.IInspectable { + override public class var IID: SUPPORT_MODULE.IID { IID_IActivationFactory } + + public func ActivateInstance() throws -> SUPPORT_MODULE.IInspectable { + return try perform(as: C_IActivationFactory.self) { pThis in + let instance = try ComPtrs.initialize { instanceAbi in + try CHECKED(pThis.pointee.lpVtbl.pointee.ActivateInstance(pThis, &instanceAbi)) + } + return .init(instance!) + } + } +} + +public func RoGetActivationFactory(_ activatableClassId: StaticString) throws -> Factory { var iid = Factory.IID let (factory) = try ComPtrs.initialize(to: C_IInspectable.self) { factoryAbi in - try CHECKED(RoGetActivationFactory(activatableClassId.get(), &iid, &factoryAbi)) + try activatableClassId.withHStringRef { activatableClassIdHStr in + try CHECKED(RoGetActivationFactory(activatableClassIdHStr, &iid, &factoryAbi)) + } } return try factory!.queryInterface() } -public func RoActivateInstance(_ 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 diff --git a/swiftwinrt/Resources/Support/Swift+Extensions.swift b/swiftwinrt/Resources/Support/Swift+Extensions.swift index 76d352eb..f9cfe064 100644 --- a/swiftwinrt/Resources/Support/Swift+Extensions.swift +++ b/swiftwinrt/Resources/Support/Swift+Extensions.swift @@ -15,6 +15,31 @@ extension String { let pwszBuffer: PCWSTR = WindowsGetStringRawBuffer(hString.get(), &length) self.init(decoding: UnsafeBufferPointer(start: pwszBuffer, count: Int(length)), as: UTF16.self) } + + public func withHStringRef(_ body: (HSTRING?) throws -> Void) rethrows { + try self.withCString(encodedAs: UTF16.self) { + var hString: HSTRING? + var header: HSTRING_HEADER = .init() + try CHECKED(WindowsCreateStringReference($0, UInt32(self.count), &header, &hString)) + try body(hString) + } + } +} + +extension StaticString { + public func withHStringRef(_ body: (HSTRING?) throws -> Void) rethrows { + var buffer: C_BINDINGS_MODULE.StaticWCharArray_512 = .init() + try withUnsafeMutableBytes(of: &buffer.Data) { (bytes:UnsafeMutableRawBufferPointer) in + let bytesPtr = bytes.assumingMemoryBound(to: WCHAR.self) + self.withUTF8Buffer { utf8buffer in + try! CHECKED(MultiByteToWideChar(UInt32(CP_UTF8), 0, utf8buffer.baseAddress, Int32(utf8buffer.count), bytesPtr.baseAddress, Int32(bytes.count))) + } + var hString: HSTRING? + var header: HSTRING_HEADER = .init() + try CHECKED(WindowsCreateStringReference(bytesPtr.baseAddress, UINT32(self.utf8CodeUnitCount), &header, &hString)) + try body(hString) + } + } } extension Bool { diff --git a/swiftwinrt/code_writers.h b/swiftwinrt/code_writers.h index ea0f2746..d56811e7 100644 --- a/swiftwinrt/code_writers.h +++ b/swiftwinrt/code_writers.h @@ -1920,7 +1920,7 @@ vtable); { interface_info factory_info{ factoryIface }; auto swift_name = get_swift_name(factory_info); - w.write("private static let %: %.% = try! RoGetActivationFactory(HString(\"%\"))\n", + w.write("private static let %: %.% = try! RoGetActivationFactory(\"%\")\n", swift_name, abi_namespace(factoryIface), factory.type, get_full_type_name(type)); for (const auto& method : factoryIface->functions) { @@ -1941,10 +1941,12 @@ vtable); { auto base_class = type.base_class; + w.write("private static let _defaultFactory: %.IActivationFactory = try! RoGetActivationFactory(\"%\")\n", + w.support, get_full_type_name(type)); w.write("%public init() {\n", has_default_constructor(base_class) ? "override " : ""); { auto indent = w.push_indent(); - auto activateInstance = w.write_temp("try! RoActivateInstance(HString(\"%\"))", get_full_type_name(type)); + auto activateInstance = "try! Self._defaultFactory.ActivateInstance()"; if (base_class) { w.write("super.init(fromAbi: %)\n", activateInstance); @@ -1992,7 +1994,7 @@ public init( { if (auto factoryIface = dynamic_cast(factory.type)) { - w.write("private static var _% : %.% = try! RoGetActivationFactory(HString(\"%\"))\n\n", + w.write("private static var _% : %.% = try! RoGetActivationFactory(\"%\")\n\n", factory.type, abi_namespace(factoryIface), factory.type, @@ -2277,7 +2279,7 @@ public init( static_info.attributed = true; auto impl_name = get_swift_name(static_info); - w.write("private static let %: %.% = try! RoGetActivationFactory(HString(\"%\"))\n", + w.write("private static let %: %.% = try! RoGetActivationFactory(\"%\")\n", impl_name, abi_namespace(statics.type), statics.type->swift_type_name(), diff --git a/tests/test_component/Sources/test_component/Windows.Foundation.Collections.swift b/tests/test_component/Sources/test_component/Windows.Foundation.Collections.swift index 48ee8636..35b2a601 100644 --- a/tests/test_component/Sources/test_component/Windows.Foundation.Collections.swift +++ b/tests/test_component/Sources/test_component/Windows.Foundation.Collections.swift @@ -35,8 +35,9 @@ public final class PropertySet : WinRTClass, IObservableMap, IMap, IIterable, IP override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("Windows.Foundation.Collections.PropertySet") override public init() { - super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.PropertySet"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } private lazy var _IObservableMap: IObservableMapString_Any! = getInterfaceForCaching() @@ -133,8 +134,9 @@ public final class StringMap : WinRTClass, IMap, IIterable, IObservableMap { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("Windows.Foundation.Collections.StringMap") override public init() { - super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.StringMap"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.foundation.collections.stringmap.lookup) @@ -229,8 +231,9 @@ public final class ValueSet : WinRTClass, IObservableMap, IMap, IIterable, IProp override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("Windows.Foundation.Collections.ValueSet") override public init() { - super.init(try! RoActivateInstance(HString("Windows.Foundation.Collections.ValueSet"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } private lazy var _IObservableMap: IObservableMapString_Any! = getInterfaceForCaching() diff --git a/tests/test_component/Sources/test_component/Windows.Foundation.swift b/tests/test_component/Sources/test_component/Windows.Foundation.swift index bdc7329f..1a92d171 100644 --- a/tests/test_component/Sources/test_component/Windows.Foundation.swift +++ b/tests/test_component/Sources/test_component/Windows.Foundation.swift @@ -34,7 +34,7 @@ public final class Deferral : WinRTClass, IClosable { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IDeferralFactory: __ABI_Windows_Foundation.IDeferralFactory = try! RoGetActivationFactory(HString("Windows.Foundation.Deferral")) + private static let _IDeferralFactory: __ABI_Windows_Foundation.IDeferralFactory = try! RoGetActivationFactory("Windows.Foundation.Deferral") public init(_ handler: DeferralCompletedHandler!) { super.init(try! Self._IDeferralFactory.CreateImpl(handler)) } @@ -83,7 +83,7 @@ public final class MemoryBuffer : WinRTClass, IClosable, IMemoryBuffer { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IMemoryBufferFactory: __ABI_Windows_Foundation.IMemoryBufferFactory = try! RoGetActivationFactory(HString("Windows.Foundation.MemoryBuffer")) + private static let _IMemoryBufferFactory: __ABI_Windows_Foundation.IMemoryBufferFactory = try! RoGetActivationFactory("Windows.Foundation.MemoryBuffer") public init(_ capacity: UInt32) { super.init(try! Self._IMemoryBufferFactory.CreateImpl(capacity)) } @@ -132,7 +132,7 @@ public final class Uri : WinRTClass, IStringable { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IUriEscapeStatics: __ABI_Windows_Foundation.IUriEscapeStatics = try! RoGetActivationFactory(HString("Windows.Foundation.Uri")) + private static let _IUriEscapeStatics: __ABI_Windows_Foundation.IUriEscapeStatics = try! RoGetActivationFactory("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) @@ -143,7 +143,7 @@ public final class Uri : WinRTClass, IStringable { return try! _IUriEscapeStatics.EscapeComponentImpl(toEscape) } - private static let _IUriRuntimeClassFactory: __ABI_Windows_Foundation.IUriRuntimeClassFactory = try! RoGetActivationFactory(HString("Windows.Foundation.Uri")) + private static let _IUriRuntimeClassFactory: __ABI_Windows_Foundation.IUriRuntimeClassFactory = try! RoGetActivationFactory("Windows.Foundation.Uri") public init(_ uri: String) { super.init(try! Self._IUriRuntimeClassFactory.CreateUriImpl(uri)) } @@ -289,7 +289,7 @@ public final class WwwFormUrlDecoder : WinRTClass, IIterable, IVectorView { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IWwwFormUrlDecoderRuntimeClassFactory: __ABI_Windows_Foundation.IWwwFormUrlDecoderRuntimeClassFactory = try! RoGetActivationFactory(HString("Windows.Foundation.WwwFormUrlDecoder")) + private static let _IWwwFormUrlDecoderRuntimeClassFactory: __ABI_Windows_Foundation.IWwwFormUrlDecoderRuntimeClassFactory = try! RoGetActivationFactory("Windows.Foundation.WwwFormUrlDecoder") public init(_ query: String) { super.init(try! Self._IWwwFormUrlDecoderRuntimeClassFactory.CreateWwwFormUrlDecoderImpl(query)) } diff --git a/tests/test_component/Sources/test_component/Windows.Storage.Search.swift b/tests/test_component/Sources/test_component/Windows.Storage.Search.swift index 74668691..27979864 100644 --- a/tests/test_component/Sources/test_component/Windows.Storage.Search.swift +++ b/tests/test_component/Sources/test_component/Windows.Storage.Search.swift @@ -39,11 +39,12 @@ public final class QueryOptions : WinRTClass { super.init(fromAbi) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("Windows.Storage.Search.QueryOptions") override public init() { - super.init(try! RoActivateInstance(HString("Windows.Storage.Search.QueryOptions"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } - private static let _IQueryOptionsFactory: __ABI_Windows_Storage_Search.IQueryOptionsFactory = try! RoGetActivationFactory(HString("Windows.Storage.Search.QueryOptions")) + private static let _IQueryOptionsFactory: __ABI_Windows_Storage_Search.IQueryOptionsFactory = try! RoGetActivationFactory("Windows.Storage.Search.QueryOptions") public init(_ query: CommonFileQuery, _ fileTypeFilter: AnyIIterable!) { super.init(try! Self._IQueryOptionsFactory.CreateCommonFileQueryImpl(query, fileTypeFilter)) } diff --git a/tests/test_component/Sources/test_component/Windows.Storage.Streams.swift b/tests/test_component/Sources/test_component/Windows.Storage.Streams.swift index c8104341..4667f209 100644 --- a/tests/test_component/Sources/test_component/Windows.Storage.Streams.swift +++ b/tests/test_component/Sources/test_component/Windows.Storage.Streams.swift @@ -34,12 +34,12 @@ public final class Buffer : WinRTClass, IBufferByteAccess, IBuffer { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IBufferFactory: __ABI_Windows_Storage_Streams.IBufferFactory = try! RoGetActivationFactory(HString("Windows.Storage.Streams.Buffer")) + private static let _IBufferFactory: __ABI_Windows_Storage_Streams.IBufferFactory = try! RoGetActivationFactory("Windows.Storage.Streams.Buffer") public init(_ capacity: UInt32) { super.init(try! Self._IBufferFactory.CreateImpl(capacity)) } - private static let _IBufferStatics: __ABI_Windows_Storage_Streams.IBufferStatics = try! RoGetActivationFactory(HString("Windows.Storage.Streams.Buffer")) + private static let _IBufferStatics: __ABI_Windows_Storage_Streams.IBufferStatics = try! RoGetActivationFactory("Windows.Storage.Streams.Buffer") /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.storage.streams.buffer.createcopyfrommemorybuffer) public static func createCopyFromMemoryBuffer(_ input: test_component.AnyIMemoryBuffer!) -> Buffer! { return try! _IBufferStatics.CreateCopyFromMemoryBufferImpl(input) diff --git a/tests/test_component/Sources/test_component/Windows.Storage.swift b/tests/test_component/Sources/test_component/Windows.Storage.swift index 1331c83d..32ce907a 100644 --- a/tests/test_component/Sources/test_component/Windows.Storage.swift +++ b/tests/test_component/Sources/test_component/Windows.Storage.swift @@ -23,7 +23,7 @@ public typealias StorageOpenOptions = __x_ABI_CWindows_CStorage_CStorageOpenOpti public typealias StreamedFileFailureMode = __x_ABI_CWindows_CStorage_CStreamedFileFailureMode /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.storage.pathio) public final class PathIO { - private static let _IPathIOStatics: __ABI_Windows_Storage.IPathIOStatics = try! RoGetActivationFactory(HString("Windows.Storage.PathIO")) + private static let _IPathIOStatics: __ABI_Windows_Storage.IPathIOStatics = try! RoGetActivationFactory("Windows.Storage.PathIO") /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.storage.pathio.readtextasync) public static func readTextAsync(_ absolutePath: String) -> AnyIAsyncOperation! { return try! _IPathIOStatics.ReadTextAsyncImpl(absolutePath) @@ -123,7 +123,7 @@ public final class StorageFile : WinRTClass, IStorageItem, test_component.IRando override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IStorageFileStatics: __ABI_Windows_Storage.IStorageFileStatics = try! RoGetActivationFactory(HString("Windows.Storage.StorageFile")) + private static let _IStorageFileStatics: __ABI_Windows_Storage.IStorageFileStatics = try! RoGetActivationFactory("Windows.Storage.StorageFile") /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.storage.storagefile.getfilefrompathasync) public static func getFileFromPathAsync(_ path: String) -> AnyIAsyncOperation! { return try! _IStorageFileStatics.GetFileFromPathAsyncImpl(path) @@ -404,7 +404,7 @@ public final class StorageFolder : WinRTClass, IStorageItem, IStorageFolder, tes override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static let _IStorageFolderStatics: __ABI_Windows_Storage.IStorageFolderStatics = try! RoGetActivationFactory(HString("Windows.Storage.StorageFolder")) + private static let _IStorageFolderStatics: __ABI_Windows_Storage.IStorageFolderStatics = try! RoGetActivationFactory("Windows.Storage.StorageFolder") /// [Open Microsoft documentation](https://learn.microsoft.com/uwp/api/windows.storage.storagefolder.getfolderfrompathasync) public static func getFolderFromPathAsync(_ path: String) -> AnyIAsyncOperation! { return try! _IStorageFolderStatics.GetFolderFromPathAsyncImpl(path) diff --git a/tests/test_component/Sources/test_component/test_component.swift b/tests/test_component/Sources/test_component/test_component.swift index 9bfcca23..452f1de4 100644 --- a/tests/test_component/Sources/test_component/test_component.swift +++ b/tests/test_component/Sources/test_component/test_component.swift @@ -9,7 +9,7 @@ public typealias Signed = __x_ABI_Ctest__component_CSigned public typealias SwiftifiableNames = __x_ABI_Ctest__component_CSwiftifiableNames public typealias Unsigned = __x_ABI_Ctest__component_CUnsigned public final class AsyncMethods { - private static let _IAsyncMethodsStatics: __ABI_test_component.IAsyncMethodsStatics = try! RoGetActivationFactory(HString("test_component.AsyncMethods")) + private static let _IAsyncMethodsStatics: __ABI_test_component.IAsyncMethodsStatics = try! RoGetActivationFactory("test_component.AsyncMethods") public static func getCompletedAsync(_ result: Int32) -> AnyIAsyncOperation! { return try! _IAsyncMethodsStatics.GetCompletedAsyncImpl(result) } @@ -136,7 +136,7 @@ open class Base : WinRTClass { default: return super.queryInterface(iid) } } - private static var _IBaseProtectedFactory : __ABI_test_component.IBaseProtectedFactory = try! RoGetActivationFactory(HString("test_component.Base")) + private static var _IBaseProtectedFactory : __ABI_test_component.IBaseProtectedFactory = try! RoGetActivationFactory("test_component.Base") override public init() { super.init() @@ -145,7 +145,7 @@ open class Base : WinRTClass { } } - private static let _IBaseStatics: __ABI_test_component.IBaseStatics = try! RoGetActivationFactory(HString("test_component.Base")) + private static let _IBaseStatics: __ABI_test_component.IBaseStatics = try! RoGetActivationFactory("test_component.Base") public class func createFromString(_ value: String) -> Base! { return try! _IBaseStatics.CreateFromStringImpl(value) } @@ -211,7 +211,7 @@ open class BaseCollection : WinRTClass, IVector, IIterable { override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IBaseCollectionProtectedFactory : __ABI_test_component.IBaseCollectionProtectedFactory = try! RoGetActivationFactory(HString("test_component.BaseCollection")) + private static var _IBaseCollectionProtectedFactory : __ABI_test_component.IBaseCollectionProtectedFactory = try! RoGetActivationFactory("test_component.BaseCollection") override public init() { super.init() @@ -415,7 +415,7 @@ open class BaseNoOverrides : WinRTClass { override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IBaseNoOverridesProtectedFactory : __ABI_test_component.IBaseNoOverridesProtectedFactory = try! RoGetActivationFactory(HString("test_component.BaseNoOverrides")) + private static var _IBaseNoOverridesProtectedFactory : __ABI_test_component.IBaseNoOverridesProtectedFactory = try! RoGetActivationFactory("test_component.BaseNoOverrides") override public init() { super.init() @@ -424,7 +424,7 @@ open class BaseNoOverrides : WinRTClass { } } - private static let _IBaseNoOverridesStatics: __ABI_test_component.IBaseNoOverridesStatics = try! RoGetActivationFactory(HString("test_component.BaseNoOverrides")) + private static let _IBaseNoOverridesStatics: __ABI_test_component.IBaseNoOverridesStatics = try! RoGetActivationFactory("test_component.BaseNoOverrides") public class func createFromString(_ value: String) -> BaseNoOverrides! { return try! _IBaseNoOverridesStatics.CreateFromStringImpl(value) } @@ -569,7 +569,7 @@ public final class BaseObservableCollection : WinRTClass, IObservableVector, IVe } public final class BufferTester { - private static let _IBufferTesterStatics: __ABI_test_component.IBufferTesterStatics = try! RoGetActivationFactory(HString("test_component.BufferTester")) + private static let _IBufferTesterStatics: __ABI_test_component.IBufferTesterStatics = try! RoGetActivationFactory("test_component.BufferTester") public static func getDataFrom(_ buffer: test_component.AnyIBuffer!, _ index: UInt32) -> UInt8 { return try! _IBufferTesterStatics.GetDataFromImpl(buffer, index) } @@ -602,11 +602,12 @@ public final class Class : WinRTClass, IBasic { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("test_component.Class") override public init() { - super.init(try! RoActivateInstance(HString("test_component.Class"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } - private static let _IClassFactory: __ABI_test_component.IClassFactory = try! RoGetActivationFactory(HString("test_component.Class")) + private static let _IClassFactory: __ABI_test_component.IClassFactory = try! RoGetActivationFactory("test_component.Class") public init(_ name: String) { super.init(try! Self._IClassFactory.CreateInstanceImpl(name)) } @@ -631,12 +632,12 @@ public final class Class : WinRTClass, IBasic { super.init(try! Self._IClassFactory.CreateInstance6Impl(arg, dummy1, dummy2, dummy3, dummy4, dummy5, dummy6)) } - private static let _IClassFactory2: __ABI_test_component.IClassFactory2 = try! RoGetActivationFactory(HString("test_component.Class")) + private static let _IClassFactory2: __ABI_test_component.IClassFactory2 = try! RoGetActivationFactory("test_component.Class") public init(_ name: String, _ fruit: Fruit, _ implementation: AnyIIAmImplementable!) { super.init(try! Self._IClassFactory2.CreateInstanceImpl(name, fruit, implementation)) } - private static let _IClassStatics: __ABI_test_component.IClassStatics = try! RoGetActivationFactory(HString("test_component.Class")) + private static let _IClassStatics: __ABI_test_component.IClassStatics = try! RoGetActivationFactory("test_component.Class") public static func staticTest() { try! _IClassStatics.StaticTestImpl() } @@ -653,7 +654,7 @@ public final class Class : WinRTClass, IBasic { get { try! _IClassStatics.get_StaticPropertyImpl() } } - private static let _IClassStatics2: __ABI_test_component.IClassStatics2 = try! RoGetActivationFactory(HString("test_component.Class")) + private static let _IClassStatics2: __ABI_test_component.IClassStatics2 = try! RoGetActivationFactory("test_component.Class") public static func staticTestReturnFloat() -> Float { return try! _IClassStatics2.StaticTestReturnFloatImpl() } @@ -835,11 +836,12 @@ public final class CollectionTester : WinRTClass { super.init(fromAbi) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("test_component.CollectionTester") override public init() { - super.init(try! RoActivateInstance(HString("test_component.CollectionTester"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } - private static let _ICollectionTesterStatics: __ABI_test_component.ICollectionTesterStatics = try! RoGetActivationFactory(HString("test_component.CollectionTester")) + private static let _ICollectionTesterStatics: __ABI_test_component.ICollectionTesterStatics = try! RoGetActivationFactory("test_component.CollectionTester") public static func inMap(_ value: AnyIMap!) -> String { return try! _ICollectionTesterStatics.InMapImpl(value) } @@ -932,11 +934,12 @@ public final class Derived : test_component.Base { super.init(fromAbi: fromAbi) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("test_component.Derived") override public init() { - super.init(fromAbi: try! RoActivateInstance(HString("test_component.Derived"))) + super.init(fromAbi: try! Self._defaultFactory.ActivateInstance()) } - private static let _IDerivedStatics: __ABI_test_component.IDerivedStatics = try! RoGetActivationFactory(HString("test_component.Derived")) + private static let _IDerivedStatics: __ABI_test_component.IDerivedStatics = try! RoGetActivationFactory("test_component.Derived") override public static func createFromString(_ value: String) -> Derived! { return try! _IDerivedStatics.CreateFromStringImpl(value) } @@ -1028,7 +1031,7 @@ public final class EventTester : WinRTClass { super.init(fromAbi) } - private static let _IEventTesterFactory: __ABI_test_component.IEventTesterFactory = try! RoGetActivationFactory(HString("test_component.EventTester")) + private static let _IEventTesterFactory: __ABI_test_component.IEventTesterFactory = try! RoGetActivationFactory("test_component.EventTester") public init(_ impl: AnyIIAmImplementable!) { super.init(try! Self._IEventTesterFactory.CreateInstanceImpl(impl)) } @@ -1080,8 +1083,9 @@ public final class NoopClosable : WinRTClass, test_component.IClosable { override public func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("test_component.NoopClosable") override public init() { - super.init(try! RoActivateInstance(HString("test_component.NoopClosable"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } public func close() throws { @@ -1094,7 +1098,7 @@ public final class NoopClosable : WinRTClass, test_component.IClosable { } public final class NullValues { - private static let _INullValuesStatics: __ABI_test_component.INullValuesStatics = try! RoGetActivationFactory(HString("test_component.NullValues")) + private static let _INullValuesStatics: __ABI_test_component.INullValuesStatics = try! RoGetActivationFactory("test_component.NullValues") public static func isObjectNull(_ value: Any!) -> Bool { return try! _INullValuesStatics.IsObjectNullImpl(value) } @@ -1160,11 +1164,12 @@ public final class Simple : WinRTClass { super.init(fromAbi) } + private static let _defaultFactory: test_component.IActivationFactory = try! RoGetActivationFactory("test_component.Simple") override public init() { - super.init(try! RoActivateInstance(HString("test_component.Simple"))) + super.init(try! Self._defaultFactory.ActivateInstance()) } - private static let _ISimpleStatics: __ABI_test_component.ISimpleStatics = try! RoGetActivationFactory(HString("test_component.Simple")) + private static let _ISimpleStatics: __ABI_test_component.ISimpleStatics = try! RoGetActivationFactory("test_component.Simple") public static func fireStaticEvent() { try! _ISimpleStatics.FireStaticEventImpl() } @@ -1282,7 +1287,7 @@ public final class Simple : WinRTClass { } public final class StaticClass { - private static let _IStaticClassStatics: __ABI_test_component.IStaticClassStatics = try! RoGetActivationFactory(HString("test_component.StaticClass")) + private static let _IStaticClassStatics: __ABI_test_component.IStaticClassStatics = try! RoGetActivationFactory("test_component.StaticClass") public static func inEnum(_ value: Signed) -> String { return try! _IStaticClassStatics.InEnumImpl(value) } @@ -1343,7 +1348,7 @@ open class UnsealedDerived : test_component.Base { default: return super.queryInterface(iid) } } - private static var _IUnsealedDerivedFactory : __ABI_test_component.IUnsealedDerivedFactory = try! RoGetActivationFactory(HString("test_component.UnsealedDerived")) + private static var _IUnsealedDerivedFactory : __ABI_test_component.IUnsealedDerivedFactory = try! RoGetActivationFactory("test_component.UnsealedDerived") override public init() { super.init(composing: Self.Composable.self) { baseInterface, innerInterface in @@ -1439,7 +1444,7 @@ open class UnsealedDerived2 : test_component.UnsealedDerived { override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IUnsealedDerived2Factory : __ABI_test_component.IUnsealedDerived2Factory = try! RoGetActivationFactory(HString("test_component.UnsealedDerived2")) + private static var _IUnsealedDerived2Factory : __ABI_test_component.IUnsealedDerived2Factory = try! RoGetActivationFactory("test_component.UnsealedDerived2") override public init(_ prop: Int32) { super.init(composing: Self.Composable.self) { baseInterface, innerInterface in @@ -1447,7 +1452,7 @@ open class UnsealedDerived2 : test_component.UnsealedDerived { } } - private static var _IUnsealedDerived2ProtectedFactory : __ABI_test_component.IUnsealedDerived2ProtectedFactory = try! RoGetActivationFactory(HString("test_component.UnsealedDerived2")) + private static var _IUnsealedDerived2ProtectedFactory : __ABI_test_component.IUnsealedDerived2ProtectedFactory = try! RoGetActivationFactory("test_component.UnsealedDerived2") override public init() { super.init(composing: Self.Composable.self) { baseInterface, innerInterface in @@ -1508,7 +1513,7 @@ open class UnsealedDerivedFromNoConstructor : test_component.UnsealedDerivedNoCo override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IUnsealedDerivedFromNoConstructorFactory : __ABI_test_component.IUnsealedDerivedFromNoConstructorFactory = try! RoGetActivationFactory(HString("test_component.UnsealedDerivedFromNoConstructor")) + private static var _IUnsealedDerivedFromNoConstructorFactory : __ABI_test_component.IUnsealedDerivedFromNoConstructorFactory = try! RoGetActivationFactory("test_component.UnsealedDerivedFromNoConstructor") public init() { super.init(composing: Self.Composable.self) { baseInterface, innerInterface in @@ -1565,7 +1570,7 @@ open class UnsealedDerivedNoConstructor : test_component.Base { override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IUnsealedDerivedNoConstructorFactory : __ABI_test_component.IUnsealedDerivedNoConstructorFactory = try! RoGetActivationFactory(HString("test_component.UnsealedDerivedNoConstructor")) + private static var _IUnsealedDerivedNoConstructorFactory : __ABI_test_component.IUnsealedDerivedNoConstructorFactory = try! RoGetActivationFactory("test_component.UnsealedDerivedNoConstructor") internal enum IBaseOverrides : ComposableImpl { internal typealias CABI = __x_ABI_Ctest__component_CIBaseOverrides @@ -1616,7 +1621,7 @@ open class UnsealedDerivedNoOverrides : test_component.BaseNoOverrides { override open func queryInterface(_ iid: test_component.IID) -> IUnknownRef? { return super.queryInterface(iid) } - private static var _IUnsealedDerivedNoOverridesProtectedFactory : __ABI_test_component.IUnsealedDerivedNoOverridesProtectedFactory = try! RoGetActivationFactory(HString("test_component.UnsealedDerivedNoOverrides")) + private static var _IUnsealedDerivedNoOverridesProtectedFactory : __ABI_test_component.IUnsealedDerivedNoOverridesProtectedFactory = try! RoGetActivationFactory("test_component.UnsealedDerivedNoOverrides") override public init() { super.init(composing: Self.Composable.self) { baseInterface, innerInterface in