From 644b9ea5f3931365a4126fb15259d8cab00b1f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:28:54 +0300 Subject: [PATCH 01/17] Attach `NativeFinalizer` to `IUnknown` objects --- lib/src/com/iunknown.dart | 44 ++++++++++++++++++------------ tool/generator/data/com_types.json | 1 - 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/src/com/iunknown.dart b/lib/src/com/iunknown.dart index 889cfa8e6c..f85225f93a 100644 --- a/lib/src/com/iunknown.dart +++ b/lib/src/com/iunknown.dart @@ -1,25 +1,21 @@ // iunknown.dart -// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY. - -// ignore_for_file: unused_import // ignore_for_file: constant_identifier_names, non_constant_identifier_names -// ignore_for_file: no_leading_underscores_for_local_identifiers import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import '../callbacks.dart'; import '../combase.dart'; -import '../constants.dart'; import '../exceptions.dart'; import '../guid.dart'; import '../macros.dart'; -import '../structs.g.dart'; import '../utils.dart'; -import '../variant.dart'; -import '../win32/ole32.g.dart'; + +typedef WinCoTaskMemFreeNative = Void Function(Pointer pv); +final ole32Lib = DynamicLibrary.open('ole32.dll'); +final winCoTaskMemFree = + ole32Lib.lookup>('CoTaskMemFree'); /// @nodoc const IID_IUnknown = '{00000000-0000-0000-c000-000000000046}'; @@ -33,15 +29,24 @@ const IID_IUnknown = '{00000000-0000-0000-c000-000000000046}'; /// /// {@category Interface} /// {@category com} -class IUnknown { +class IUnknown implements Finalizable { // vtable begins at 0, is 3 entries long. Pointer ptr; - IUnknown(this.ptr); + IUnknown(this.ptr) { + _finalizer.attach(this, ptr.cast(), detach: this, externalSize: 8); + } + + static final _finalizer = NativeFinalizer(winCoTaskMemFree.cast()); factory IUnknown.from(IUnknown interface) => IUnknown(interface.toInterface(IID_IUnknown)); + /// Queries a COM object for a pointer to one of its interface; identifying + /// the interface by a reference to its interface identifier (IID). + /// + /// If the COM object implements the interface, then it returns a pointer to + /// that interface after calling `addRef` on it. int queryInterface(Pointer riid, Pointer ppvObject) => ptr .ref.vtable .elementAt(0) @@ -55,12 +60,17 @@ class IUnknown { int Function(Pointer, Pointer riid, Pointer ppvObject)>()(ptr.ref.lpVtbl, riid, ppvObject); + /// Increments the reference count for an interface pointer to a COM object. + /// + /// You should call this method whenever you make a copy of an interface + /// pointer. int addRef() => ptr.ref.vtable .elementAt(1) .cast>>() .value .asFunction()(ptr.ref.lpVtbl); + /// Decrements the reference count for an interface on a COM object. int release() => ptr.ref.vtable .elementAt(2) .cast>>() @@ -71,16 +81,16 @@ class IUnknown { /// /// Takes a string (typically a constant such as `IID_IModalWindow`) and does /// a COM QueryInterface to return a reference to that interface. This method - /// reduces the boilerplate associated with calling QueryInterface manually. + /// reduces the boilerplate associated with calling `queryInterface` manually. Pointer toInterface(String iid) { - final pIID = convertToIID(iid); - final pObject = calloc(); + final nativeGuidPtr = convertToIID(iid); + final objectPtr = calloc(); try { - final hr = queryInterface(pIID, pObject.cast()); + final hr = queryInterface(nativeGuidPtr, objectPtr.cast()); if (FAILED(hr)) throw WindowsException(hr); - return pObject; + return objectPtr; } finally { - free(pIID); + free(nativeGuidPtr); } } } diff --git a/tool/generator/data/com_types.json b/tool/generator/data/com_types.json index d06da750a1..fadc663582 100644 --- a/tool/generator/data/com_types.json +++ b/tool/generator/data/com_types.json @@ -67,7 +67,6 @@ "Windows.Win32.System.Com.IStream": "The IStream interface lets you read and write data to stream objects. Stream objects contain the data in a structured storage object, where storages provide the structure. Simple data can be written directly to a stream but, most frequently, streams are elements nested within a storage object. They are similar to standard files.", "Windows.Win32.System.Com.ISupportErrorInfo": "Ensures that error information can be propagated up the call chain correctly. Automation objects that use the error handling interfaces must implement ISupportErrorInfo.", "Windows.Win32.System.Com.ITypeInfo": "This section describes ITypeInfo, an interface typically used for reading information about objects. For example, an object browser tool can use ITypeInfo to extract information about the characteristics and capabilities of objects from type libraries.", - "Windows.Win32.System.Com.IUnknown": "Enables clients to get pointers to other interfaces on a given object through the QueryInterface method, and manage the existence of the object through the AddRef and Release methods. All other COM interfaces are inherited, directly or indirectly, from IUnknown. Therefore, the three methods in IUnknown are the first entries in the vtable for every interface.", "Windows.Win32.System.Com.IUri": "Exposes methods and properties used to parse and build Uniform Resource Identifiers (URIs).", "Windows.Win32.System.Ole.IEnumVARIANT": "Provides a method for enumerating a collection of variants, including heterogeneous collections of objects and intrinsic types. Callers of this interface do not need to know the specific type (or types) of the elements in the collection.", "Windows.Win32.System.Ole.IProvideClassInfo": "Provides access to the type information for an object's coclass entry in its type library.", From e8110d0e185cc066ae254d512210ecc1af2facce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:30:30 +0300 Subject: [PATCH 02/17] Refactor WinRT helper functions --- lib/src/winrt_helpers.dart | 91 +++++++++++++------------------------- 1 file changed, 30 insertions(+), 61 deletions(-) diff --git a/lib/src/winrt_helpers.dart b/lib/src/winrt_helpers.dart index af963c0a45..43d578aa4e 100644 --- a/lib/src/winrt_helpers.dart +++ b/lib/src/winrt_helpers.dart @@ -20,7 +20,6 @@ import 'types.dart'; import 'utils.dart'; import 'win32/api_ms_win_core_winrt_l1_1_0.g.dart'; import 'win32/api_ms_win_core_winrt_string_l1_1_0.g.dart'; -import 'win32/ole32.g.dart'; import 'winrt/foundation/winrt_enum.dart'; /// Initializes the Windows Runtime on the current thread with a single-threaded @@ -48,64 +47,35 @@ extension WinRTStringConversion on Pointer { /// /// {@category winrt} Pointer CreateObject(String className, String iid) { - final hstrClass = calloc(); - final lpClassName = className.toNativeUtf16(); - final inspectablePtr = calloc(); - final riid = calloc(); - final classPtr = calloc(); - final iidPtr = iid.toNativeUtf16(); - final classNamePtr = className.toNativeUtf16(); - - try { - // Create a HSTRING representing the object - var hr = WindowsCreateString(classNamePtr, className.length, hstrClass); - if (FAILED(hr)) { - throw WindowsException(hr); - } - // Activates the specified Windows Runtime class. This returns the WinRT - // IInspectable interface, which is a subclass of IUnknown. - hr = RoActivateInstance(hstrClass.value, inspectablePtr.cast()); - if (FAILED(hr)) { - throw WindowsException(hr); - } - - // Create an IID for the interface required - hr = IIDFromString(iidPtr, riid); - if (FAILED(hr)) { - throw WindowsException(hr); - } - - // Now use IInspectable to navigate to the relevant interface - final inspectable = IInspectable(inspectablePtr); - hr = inspectable.queryInterface(riid, classPtr); - if (FAILED(hr)) { - throw WindowsException(hr); - } - - // Return a pointer to the relevant class - return classPtr.cast(); - } finally { - free(classNamePtr); - free(iidPtr); - free(riid); - free(inspectablePtr); - free(lpClassName); - free(hstrClass); - } + // Activates the specified Windows Runtime class + final inspectablePtr = ActivateClass(className); + // Now use IInspectable to navigate to the relevant interface + final inspectable = IInspectable(inspectablePtr); + final objectPtr = inspectable.toInterface(iid); + inspectable.release(); + // Return a pointer to the relevant class + return objectPtr; } +/// Activates the specified Windows Runtime class in the [className]. +/// +/// This returns the WinRT `IInspectable` interface, which is a subclass of +/// `IUnknown`. +/// +/// It is the caller's responsibility to deallocate the returned pointer when +/// they are finished with it. A FFI `Arena` may be passed as a custom allocator +/// for ease of memory management. +/// +/// {@category winrt} Pointer ActivateClass(String className, {Allocator allocator = calloc}) { - final inspectablePtr = allocator(); - + // Create a HSTRING representing the object final hClassName = convertToHString(className); + try { - // Create a HSTRING representing the object - // Activates the specified Windows Runtime class. This returns the WinRT - // IInspectable interface, which is a subclass of IUnknown. + final inspectablePtr = allocator(); final hr = RoActivateInstance(hClassName, inspectablePtr.cast()); if (FAILED(hr)) throw WindowsException(hr); - // Return a pointer to the relevant class return inspectablePtr; } finally { @@ -130,21 +100,20 @@ Pointer ActivateClass(String className, /// {@category winrt} Pointer CreateActivationFactory(String className, String iid, {Allocator allocator = calloc}) { + // Create a HSTRING representing the object final hClassName = convertToHString(className); - final pIID = calloc()..ref.setGUID(iid); - final pActivationFactory = allocator(); + final nativeGuidPtr = GUIDFromString(iid); + final activationFactoryPtr = allocator(); try { - final hr = - RoGetActivationFactory(hClassName, pIID, pActivationFactory.cast()); - if (FAILED(hr)) { - throw WindowsException(hr); - } - - return pActivationFactory; + final hr = RoGetActivationFactory( + hClassName, nativeGuidPtr, activationFactoryPtr.cast()); + if (FAILED(hr)) throw WindowsException(hr); + // Return a pointer to the relevant class + return activationFactoryPtr; } finally { + free(nativeGuidPtr); WindowsDeleteString(hClassName); - free(pIID); } } From 6f93f465f4f344488619674a595e9a39f1cbcfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:31:29 +0300 Subject: [PATCH 03/17] Clean up ComInterfaceProjection class --- .../lib/src/projection/com_interface.dart | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/tool/generator/lib/src/projection/com_interface.dart b/tool/generator/lib/src/projection/com_interface.dart index 3b898e8fa5..68d6ee184c 100644 --- a/tool/generator/lib/src/projection/com_interface.dart +++ b/tool/generator/lib/src/projection/com_interface.dart @@ -175,27 +175,6 @@ class ComInterfaceProjection { $shortName(interface.toInterface(IID_$shortName)); '''; - String get queryInterfaceHelper => shortName != 'IUnknown' - ? '' - : ''' - /// Cast an existing COM object to a specified interface. - /// - /// Takes a string (typically a constant such as `IID_IModalWindow`) and does - /// a COM QueryInterface to return a reference to that interface. This method - /// reduces the boilerplate associated with calling QueryInterface manually. - Pointer toInterface(String iid) { - final pIID = convertToIID(iid); - final pObject = calloc(); - try { - final hr = queryInterface(pIID, pObject.cast()); - if (FAILED(hr)) throw WindowsException(hr); - return pObject; - } finally { - free(pIID); - } - } - '''; - String get category => 'com'; String get classType => 'Interface'; @@ -231,8 +210,6 @@ class ComInterfaceProjection { $fromCOMObjectHelper ${methodProjections.map((p) => p.toString()).join('\n')} - - $queryInterfaceHelper } '''; } From f288453b716a0a045a89c48c3ce38a5cffddbac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:36:03 +0300 Subject: [PATCH 04/17] Don't free pointers in generated COM interface tests --- test/com/iapplicationactivationmanager_test.dart | 1 - test/com/iappxfactory_test.dart | 1 - test/com/iappxfile_test.dart | 1 - test/com/iappxfilesenumerator_test.dart | 1 - test/com/iappxmanifestapplication_test.dart | 1 - test/com/iappxmanifestapplicationsenumerator_test.dart | 1 - test/com/iappxmanifestospackagedependency_test.dart | 1 - test/com/iappxmanifestpackagedependenciesenumerator_test.dart | 1 - test/com/iappxmanifestpackagedependency_test.dart | 1 - test/com/iappxmanifestpackageid_test.dart | 1 - test/com/iappxmanifestproperties_test.dart | 1 - test/com/iappxmanifestreader2_test.dart | 1 - test/com/iappxmanifestreader3_test.dart | 1 - test/com/iappxmanifestreader4_test.dart | 1 - test/com/iappxmanifestreader5_test.dart | 1 - test/com/iappxmanifestreader6_test.dart | 1 - test/com/iappxmanifestreader7_test.dart | 1 - test/com/iappxmanifestreader_test.dart | 1 - test/com/iappxpackagereader_test.dart | 1 - test/com/iaudiocaptureclient_test.dart | 1 - test/com/iaudioclient_test.dart | 1 - test/com/iaudioclock_test.dart | 1 - test/com/iaudiorenderclient_test.dart | 1 - test/com/iaudiosessioncontrol_test.dart | 1 - test/com/iaudiosessionmanager_test.dart | 1 - test/com/iaudiostreamvolume_test.dart | 1 - test/com/ibindctx_test.dart | 1 - test/com/ichannelaudiovolume_test.dart | 1 - test/com/iclassfactory_test.dart | 1 - test/com/iconnectionpoint_test.dart | 1 - test/com/iconnectionpointcontainer_test.dart | 1 - test/com/idesktopwallpaper_test.dart | 1 - test/com/idispatch_test.dart | 1 - test/com/ienumidlist_test.dart | 1 - test/com/ienummoniker_test.dart | 1 - test/com/ienumnetworkconnections_test.dart | 1 - test/com/ienumnetworks_test.dart | 1 - test/com/ienumresources_test.dart | 1 - test/com/ienumspellingerror_test.dart | 1 - test/com/ienumstring_test.dart | 1 - test/com/ienumvariant_test.dart | 1 - test/com/ienumwbemclassobject_test.dart | 1 - test/com/ierrorinfo_test.dart | 1 - test/com/ifiledialog2_test.dart | 1 - test/com/ifiledialog_test.dart | 1 - test/com/ifiledialogcustomize_test.dart | 1 - test/com/ifileisinuse_test.dart | 1 - test/com/ifileopendialog_test.dart | 1 - test/com/ifilesavedialog_test.dart | 1 - test/com/iinspectable_test.dart | 1 - test/com/iknownfolder_test.dart | 1 - test/com/iknownfoldermanager_test.dart | 1 - test/com/immdevice_test.dart | 1 - test/com/immdeviceenumerator_test.dart | 1 - test/com/imodalwindow_test.dart | 1 - test/com/imoniker_test.dart | 1 - test/com/inetwork_test.dart | 1 - test/com/inetworkconnection_test.dart | 1 - test/com/inetworklistmanager_test.dart | 1 - test/com/inetworklistmanagerevents_test.dart | 1 - test/com/ipersist_test.dart | 1 - test/com/ipersistfile_test.dart | 1 - test/com/ipersistmemory_test.dart | 1 - test/com/ipersiststream_test.dart | 1 - test/com/iprovideclassinfo_test.dart | 1 - test/com/irunningobjecttable_test.dart | 1 - test/com/isensor_test.dart | 1 - test/com/isensorcollection_test.dart | 1 - test/com/isensordatareport_test.dart | 1 - test/com/isensormanager_test.dart | 1 - test/com/isequentialstream_test.dart | 1 - test/com/ishellfolder_test.dart | 1 - test/com/ishellitem2_test.dart | 1 - test/com/ishellitem_test.dart | 1 - test/com/ishellitemarray_test.dart | 1 - test/com/ishellitemfilter_test.dart | 1 - test/com/ishellitemimagefactory_test.dart | 1 - test/com/ishellitemresources_test.dart | 1 - test/com/ishelllink_test.dart | 1 - test/com/ishelllinkdatalist_test.dart | 1 - test/com/ishelllinkdual_test.dart | 1 - test/com/ishellservice_test.dart | 1 - test/com/isimpleaudiovolume_test.dart | 1 - test/com/ispeechobjecttoken_test.dart | 1 - test/com/ispeechobjecttokens_test.dart | 1 - test/com/ispellchecker2_test.dart | 1 - test/com/ispellchecker_test.dart | 1 - test/com/ispellcheckerchangedeventhandler_test.dart | 1 - test/com/ispellcheckerfactory_test.dart | 1 - test/com/ispellingerror_test.dart | 2 -- test/com/ispeventsource_test.dart | 1 - test/com/ispnotifysource_test.dart | 1 - test/com/ispvoice_test.dart | 1 - test/com/istream_test.dart | 1 - test/com/isupporterrorinfo_test.dart | 1 - test/com/itypeinfo_test.dart | 1 - test/com/iunknown_test.dart | 1 - test/com/iuri_test.dart | 1 - test/com/ivirtualdesktopmanager_test.dart | 1 - test/com/iwbemclassobject_test.dart | 1 - test/com/iwbemconfigurerefresher_test.dart | 1 - test/com/iwbemcontext_test.dart | 1 - test/com/iwbemhiperfenum_test.dart | 1 - test/com/iwbemlocator_test.dart | 1 - test/com/iwbemobjectaccess_test.dart | 1 - test/com/iwbemrefresher_test.dart | 1 - test/com/iwbemservices_test.dart | 1 - tool/generator/lib/src/projection/test_interface.dart | 1 - 108 files changed, 109 deletions(-) diff --git a/test/com/iapplicationactivationmanager_test.dart b/test/com/iapplicationactivationmanager_test.dart index 3664cc24b8..4cb3a0379f 100644 --- a/test/com/iapplicationactivationmanager_test.dart +++ b/test/com/iapplicationactivationmanager_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IApplicationActivationManager.activateForProtocol', () { expect(applicationactivationmanager.activateForProtocol, isA()); }); - free(ptr); } diff --git a/test/com/iappxfactory_test.dart b/test/com/iappxfactory_test.dart index 5d3f9631f0..4747d11b4f 100644 --- a/test/com/iappxfactory_test.dart +++ b/test/com/iappxfactory_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IAppxFactory.createValidatedBlockMapReader', () { expect(appxfactory.createValidatedBlockMapReader, isA()); }); - free(ptr); } diff --git a/test/com/iappxfile_test.dart b/test/com/iappxfile_test.dart index ae25a3ca1f..544f9369f0 100644 --- a/test/com/iappxfile_test.dart +++ b/test/com/iappxfile_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IAppxFile.getStream', () { expect(appxfile.getStream, isA()); }); - free(ptr); } diff --git a/test/com/iappxfilesenumerator_test.dart b/test/com/iappxfilesenumerator_test.dart index ac59b9c6ac..1f5d3fb480 100644 --- a/test/com/iappxfilesenumerator_test.dart +++ b/test/com/iappxfilesenumerator_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IAppxFilesEnumerator.moveNext', () { expect(appxfilesenumerator.moveNext, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestapplication_test.dart b/test/com/iappxmanifestapplication_test.dart index eabdc10efc..9b257a3807 100644 --- a/test/com/iappxmanifestapplication_test.dart +++ b/test/com/iappxmanifestapplication_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IAppxManifestApplication.getAppUserModelId', () { expect(appxmanifestapplication.getAppUserModelId, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestapplicationsenumerator_test.dart b/test/com/iappxmanifestapplicationsenumerator_test.dart index 5846690626..8595355d4b 100644 --- a/test/com/iappxmanifestapplicationsenumerator_test.dart +++ b/test/com/iappxmanifestapplicationsenumerator_test.dart @@ -32,5 +32,4 @@ void main() { test('Can instantiate IAppxManifestApplicationsEnumerator.moveNext', () { expect(appxmanifestapplicationsenumerator.moveNext, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestospackagedependency_test.dart b/test/com/iappxmanifestospackagedependency_test.dart index 39740efc09..596b3b0d00 100644 --- a/test/com/iappxmanifestospackagedependency_test.dart +++ b/test/com/iappxmanifestospackagedependency_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IAppxManifestOSPackageDependency.getVersion', () { expect(appxmanifestospackagedependency.getVersion, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestpackagedependenciesenumerator_test.dart b/test/com/iappxmanifestpackagedependenciesenumerator_test.dart index c53f604911..c36809fb31 100644 --- a/test/com/iappxmanifestpackagedependenciesenumerator_test.dart +++ b/test/com/iappxmanifestpackagedependenciesenumerator_test.dart @@ -38,5 +38,4 @@ void main() { () { expect(appxmanifestpackagedependenciesenumerator.moveNext, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestpackagedependency_test.dart b/test/com/iappxmanifestpackagedependency_test.dart index 2004f565a5..4d331f12f0 100644 --- a/test/com/iappxmanifestpackagedependency_test.dart +++ b/test/com/iappxmanifestpackagedependency_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IAppxManifestPackageDependency.getMinVersion', () { expect(appxmanifestpackagedependency.getMinVersion, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestpackageid_test.dart b/test/com/iappxmanifestpackageid_test.dart index 4c74ba9ac2..77c47846a9 100644 --- a/test/com/iappxmanifestpackageid_test.dart +++ b/test/com/iappxmanifestpackageid_test.dart @@ -46,5 +46,4 @@ void main() { test('Can instantiate IAppxManifestPackageId.getPackageFamilyName', () { expect(appxmanifestpackageid.getPackageFamilyName, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestproperties_test.dart b/test/com/iappxmanifestproperties_test.dart index b6ac88ae4b..6c9fdaef99 100644 --- a/test/com/iappxmanifestproperties_test.dart +++ b/test/com/iappxmanifestproperties_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IAppxManifestProperties.getStringValue', () { expect(appxmanifestproperties.getStringValue, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader2_test.dart b/test/com/iappxmanifestreader2_test.dart index cc69b60479..4821742591 100644 --- a/test/com/iappxmanifestreader2_test.dart +++ b/test/com/iappxmanifestreader2_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IAppxManifestReader2.getQualifiedResources', () { expect(appxmanifestreader2.getQualifiedResources, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader3_test.dart b/test/com/iappxmanifestreader3_test.dart index 7b2fc873a3..33f017c161 100644 --- a/test/com/iappxmanifestreader3_test.dart +++ b/test/com/iappxmanifestreader3_test.dart @@ -30,5 +30,4 @@ void main() { test('Can instantiate IAppxManifestReader3.getTargetDeviceFamilies', () { expect(appxmanifestreader3.getTargetDeviceFamilies, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader4_test.dart b/test/com/iappxmanifestreader4_test.dart index 1e4aefeab6..55dd11ee91 100644 --- a/test/com/iappxmanifestreader4_test.dart +++ b/test/com/iappxmanifestreader4_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IAppxManifestReader4.getOptionalPackageInfo', () { expect(appxmanifestreader4.getOptionalPackageInfo, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader5_test.dart b/test/com/iappxmanifestreader5_test.dart index f099f81fe7..12c81dfa9b 100644 --- a/test/com/iappxmanifestreader5_test.dart +++ b/test/com/iappxmanifestreader5_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IAppxManifestReader5.getMainPackageDependencies', () { expect(appxmanifestreader5.getMainPackageDependencies, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader6_test.dart b/test/com/iappxmanifestreader6_test.dart index 01a18f3ed5..0affd1e734 100644 --- a/test/com/iappxmanifestreader6_test.dart +++ b/test/com/iappxmanifestreader6_test.dart @@ -27,5 +27,4 @@ void main() { expect( appxmanifestreader6.getIsNonQualifiedResourcePackage, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader7_test.dart b/test/com/iappxmanifestreader7_test.dart index e7d5b86cf8..930e0615d0 100644 --- a/test/com/iappxmanifestreader7_test.dart +++ b/test/com/iappxmanifestreader7_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IAppxManifestReader7.getHostRuntimeDependencies', () { expect(appxmanifestreader7.getHostRuntimeDependencies, isA()); }); - free(ptr); } diff --git a/test/com/iappxmanifestreader_test.dart b/test/com/iappxmanifestreader_test.dart index 23ef20b405..e72bd6c655 100644 --- a/test/com/iappxmanifestreader_test.dart +++ b/test/com/iappxmanifestreader_test.dart @@ -49,5 +49,4 @@ void main() { test('Can instantiate IAppxManifestReader.getStream', () { expect(appxmanifestreader.getStream, isA()); }); - free(ptr); } diff --git a/test/com/iappxpackagereader_test.dart b/test/com/iappxpackagereader_test.dart index dbc07a8d9a..6c656710f7 100644 --- a/test/com/iappxpackagereader_test.dart +++ b/test/com/iappxpackagereader_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IAppxPackageReader.getManifest', () { expect(appxpackagereader.getManifest, isA()); }); - free(ptr); } diff --git a/test/com/iaudiocaptureclient_test.dart b/test/com/iaudiocaptureclient_test.dart index 2c30c555a9..5ad85fb9f5 100644 --- a/test/com/iaudiocaptureclient_test.dart +++ b/test/com/iaudiocaptureclient_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IAudioCaptureClient.getNextPacketSize', () { expect(audiocaptureclient.getNextPacketSize, isA()); }); - free(ptr); } diff --git a/test/com/iaudioclient_test.dart b/test/com/iaudioclient_test.dart index 12f8fe642e..4006bd2f3b 100644 --- a/test/com/iaudioclient_test.dart +++ b/test/com/iaudioclient_test.dart @@ -58,5 +58,4 @@ void main() { test('Can instantiate IAudioClient.getService', () { expect(audioclient.getService, isA()); }); - free(ptr); } diff --git a/test/com/iaudioclock_test.dart b/test/com/iaudioclock_test.dart index 18232836f3..59c162b545 100644 --- a/test/com/iaudioclock_test.dart +++ b/test/com/iaudioclock_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IAudioClock.getCharacteristics', () { expect(audioclock.getCharacteristics, isA()); }); - free(ptr); } diff --git a/test/com/iaudiorenderclient_test.dart b/test/com/iaudiorenderclient_test.dart index 374de4b841..05b82ab296 100644 --- a/test/com/iaudiorenderclient_test.dart +++ b/test/com/iaudiorenderclient_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IAudioRenderClient.releaseBuffer', () { expect(audiorenderclient.releaseBuffer, isA()); }); - free(ptr); } diff --git a/test/com/iaudiosessioncontrol_test.dart b/test/com/iaudiosessioncontrol_test.dart index b665d23c46..6f43216a36 100644 --- a/test/com/iaudiosessioncontrol_test.dart +++ b/test/com/iaudiosessioncontrol_test.dart @@ -54,5 +54,4 @@ void main() { expect(audiosessioncontrol.unregisterAudioSessionNotification, isA()); }); - free(ptr); } diff --git a/test/com/iaudiosessionmanager_test.dart b/test/com/iaudiosessionmanager_test.dart index 2eac2947b6..141c56095d 100644 --- a/test/com/iaudiosessionmanager_test.dart +++ b/test/com/iaudiosessionmanager_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IAudioSessionManager.getSimpleAudioVolume', () { expect(audiosessionmanager.getSimpleAudioVolume, isA()); }); - free(ptr); } diff --git a/test/com/iaudiostreamvolume_test.dart b/test/com/iaudiostreamvolume_test.dart index 818c29711f..7110764a35 100644 --- a/test/com/iaudiostreamvolume_test.dart +++ b/test/com/iaudiostreamvolume_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IAudioStreamVolume.getAllVolumes', () { expect(audiostreamvolume.getAllVolumes, isA()); }); - free(ptr); } diff --git a/test/com/ibindctx_test.dart b/test/com/ibindctx_test.dart index a0d37e0ce6..b725288fff 100644 --- a/test/com/ibindctx_test.dart +++ b/test/com/ibindctx_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate IBindCtx.revokeObjectParam', () { expect(bindctx.revokeObjectParam, isA()); }); - free(ptr); } diff --git a/test/com/ichannelaudiovolume_test.dart b/test/com/ichannelaudiovolume_test.dart index e4f4c1bf7b..765a7bec37 100644 --- a/test/com/ichannelaudiovolume_test.dart +++ b/test/com/ichannelaudiovolume_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IChannelAudioVolume.getAllVolumes', () { expect(channelaudiovolume.getAllVolumes, isA()); }); - free(ptr); } diff --git a/test/com/iclassfactory_test.dart b/test/com/iclassfactory_test.dart index 79733ea49f..3e861daa1c 100644 --- a/test/com/iclassfactory_test.dart +++ b/test/com/iclassfactory_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IClassFactory.lockServer', () { expect(classfactory.lockServer, isA()); }); - free(ptr); } diff --git a/test/com/iconnectionpoint_test.dart b/test/com/iconnectionpoint_test.dart index 364f965ff5..14e205e9f7 100644 --- a/test/com/iconnectionpoint_test.dart +++ b/test/com/iconnectionpoint_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IConnectionPoint.enumConnections', () { expect(connectionpoint.enumConnections, isA()); }); - free(ptr); } diff --git a/test/com/iconnectionpointcontainer_test.dart b/test/com/iconnectionpointcontainer_test.dart index 4dae4b1191..594230b46c 100644 --- a/test/com/iconnectionpointcontainer_test.dart +++ b/test/com/iconnectionpointcontainer_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IConnectionPointContainer.findConnectionPoint', () { expect(connectionpointcontainer.findConnectionPoint, isA()); }); - free(ptr); } diff --git a/test/com/idesktopwallpaper_test.dart b/test/com/idesktopwallpaper_test.dart index d80116da43..3579d0f461 100644 --- a/test/com/idesktopwallpaper_test.dart +++ b/test/com/idesktopwallpaper_test.dart @@ -70,5 +70,4 @@ void main() { test('Can instantiate IDesktopWallpaper.enable', () { expect(desktopwallpaper.enable, isA()); }); - free(ptr); } diff --git a/test/com/idispatch_test.dart b/test/com/idispatch_test.dart index a939aae41e..43adf60d00 100644 --- a/test/com/idispatch_test.dart +++ b/test/com/idispatch_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IDispatch.invoke', () { expect(dispatch.invoke, isA()); }); - free(ptr); } diff --git a/test/com/ienumidlist_test.dart b/test/com/ienumidlist_test.dart index f638aeb848..47855883e7 100644 --- a/test/com/ienumidlist_test.dart +++ b/test/com/ienumidlist_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumIDList.clone', () { expect(enumidlist.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienummoniker_test.dart b/test/com/ienummoniker_test.dart index a75a9b7f9c..31b7d1590f 100644 --- a/test/com/ienummoniker_test.dart +++ b/test/com/ienummoniker_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumMoniker.clone', () { expect(enummoniker.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumnetworkconnections_test.dart b/test/com/ienumnetworkconnections_test.dart index d3fff25536..f5813d1d94 100644 --- a/test/com/ienumnetworkconnections_test.dart +++ b/test/com/ienumnetworkconnections_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumNetworkConnections.clone', () { expect(enumnetworkconnections.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumnetworks_test.dart b/test/com/ienumnetworks_test.dart index 641fcd6325..d8aef40fdd 100644 --- a/test/com/ienumnetworks_test.dart +++ b/test/com/ienumnetworks_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumNetworks.clone', () { expect(enumnetworks.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumresources_test.dart b/test/com/ienumresources_test.dart index 82d2dde14a..52e0db0b35 100644 --- a/test/com/ienumresources_test.dart +++ b/test/com/ienumresources_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumResources.clone', () { expect(enumresources.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumspellingerror_test.dart b/test/com/ienumspellingerror_test.dart index d229cc40a1..ae6e10d611 100644 --- a/test/com/ienumspellingerror_test.dart +++ b/test/com/ienumspellingerror_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IEnumSpellingError.next', () { expect(enumspellingerror.next, isA()); }); - free(ptr); } diff --git a/test/com/ienumstring_test.dart b/test/com/ienumstring_test.dart index f9866a8ae3..bce0649b0e 100644 --- a/test/com/ienumstring_test.dart +++ b/test/com/ienumstring_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumString.clone', () { expect(enumstring.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumvariant_test.dart b/test/com/ienumvariant_test.dart index e3050638a6..7336d68ba2 100644 --- a/test/com/ienumvariant_test.dart +++ b/test/com/ienumvariant_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IEnumVARIANT.clone', () { expect(enumvariant.clone, isA()); }); - free(ptr); } diff --git a/test/com/ienumwbemclassobject_test.dart b/test/com/ienumwbemclassobject_test.dart index 0d1619857e..5079dbd10d 100644 --- a/test/com/ienumwbemclassobject_test.dart +++ b/test/com/ienumwbemclassobject_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IEnumWbemClassObject.skip', () { expect(enumwbemclassobject.skip, isA()); }); - free(ptr); } diff --git a/test/com/ierrorinfo_test.dart b/test/com/ierrorinfo_test.dart index 362943d2e9..3113f8f2fd 100644 --- a/test/com/ierrorinfo_test.dart +++ b/test/com/ierrorinfo_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IErrorInfo.getHelpContext', () { expect(errorinfo.getHelpContext, isA()); }); - free(ptr); } diff --git a/test/com/ifiledialog2_test.dart b/test/com/ifiledialog2_test.dart index 2a617338fb..7b3d53fa71 100644 --- a/test/com/ifiledialog2_test.dart +++ b/test/com/ifiledialog2_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IFileDialog2.setNavigationRoot', () { expect(filedialog2.setNavigationRoot, isA()); }); - free(ptr); } diff --git a/test/com/ifiledialog_test.dart b/test/com/ifiledialog_test.dart index 9db1e21986..6f13c83c5f 100644 --- a/test/com/ifiledialog_test.dart +++ b/test/com/ifiledialog_test.dart @@ -91,5 +91,4 @@ void main() { test('Can instantiate IFileDialog.setFilter', () { expect(filedialog.setFilter, isA()); }); - free(ptr); } diff --git a/test/com/ifiledialogcustomize_test.dart b/test/com/ifiledialogcustomize_test.dart index 7fdfc7b239..41f429fb61 100644 --- a/test/com/ifiledialogcustomize_test.dart +++ b/test/com/ifiledialogcustomize_test.dart @@ -103,5 +103,4 @@ void main() { test('Can instantiate IFileDialogCustomize.setControlItemText', () { expect(filedialogcustomize.setControlItemText, isA()); }); - free(ptr); } diff --git a/test/com/ifileisinuse_test.dart b/test/com/ifileisinuse_test.dart index a3a40f0929..1b9b496890 100644 --- a/test/com/ifileisinuse_test.dart +++ b/test/com/ifileisinuse_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IFileIsInUse.closeFile', () { expect(fileisinuse.closeFile, isA()); }); - free(ptr); } diff --git a/test/com/ifileopendialog_test.dart b/test/com/ifileopendialog_test.dart index 6b8837dca0..afb070c394 100644 --- a/test/com/ifileopendialog_test.dart +++ b/test/com/ifileopendialog_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IFileOpenDialog.getSelectedItems', () { expect(fileopendialog.getSelectedItems, isA()); }); - free(ptr); } diff --git a/test/com/ifilesavedialog_test.dart b/test/com/ifilesavedialog_test.dart index 9cbf98d217..4cd9410d2a 100644 --- a/test/com/ifilesavedialog_test.dart +++ b/test/com/ifilesavedialog_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IFileSaveDialog.applyProperties', () { expect(filesavedialog.applyProperties, isA()); }); - free(ptr); } diff --git a/test/com/iinspectable_test.dart b/test/com/iinspectable_test.dart index fa91232185..729b03a666 100644 --- a/test/com/iinspectable_test.dart +++ b/test/com/iinspectable_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IInspectable.getTrustLevel', () { expect(inspectable.getTrustLevel, isA()); }); - free(ptr); } diff --git a/test/com/iknownfolder_test.dart b/test/com/iknownfolder_test.dart index 214fd63271..9cc6a18792 100644 --- a/test/com/iknownfolder_test.dart +++ b/test/com/iknownfolder_test.dart @@ -49,5 +49,4 @@ void main() { test('Can instantiate IKnownFolder.getFolderDefinition', () { expect(knownfolder.getFolderDefinition, isA()); }); - free(ptr); } diff --git a/test/com/iknownfoldermanager_test.dart b/test/com/iknownfoldermanager_test.dart index c02c9c62d4..db31de9a55 100644 --- a/test/com/iknownfoldermanager_test.dart +++ b/test/com/iknownfoldermanager_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate IKnownFolderManager.redirect', () { expect(knownfoldermanager.redirect, isA()); }); - free(ptr); } diff --git a/test/com/immdevice_test.dart b/test/com/immdevice_test.dart index 411362e52b..85eab534a4 100644 --- a/test/com/immdevice_test.dart +++ b/test/com/immdevice_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IMMDevice.getState', () { expect(mmdevice.getState, isA()); }); - free(ptr); } diff --git a/test/com/immdeviceenumerator_test.dart b/test/com/immdeviceenumerator_test.dart index e042ec253d..11566b7dd7 100644 --- a/test/com/immdeviceenumerator_test.dart +++ b/test/com/immdeviceenumerator_test.dart @@ -43,5 +43,4 @@ void main() { expect(mmdeviceenumerator.unregisterEndpointNotificationCallback, isA()); }); - free(ptr); } diff --git a/test/com/imodalwindow_test.dart b/test/com/imodalwindow_test.dart index 6fc59e3d8a..b5bf526db2 100644 --- a/test/com/imodalwindow_test.dart +++ b/test/com/imodalwindow_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IModalWindow.show', () { expect(modalwindow.show, isA()); }); - free(ptr); } diff --git a/test/com/imoniker_test.dart b/test/com/imoniker_test.dart index f8e71c373a..614748e1b6 100644 --- a/test/com/imoniker_test.dart +++ b/test/com/imoniker_test.dart @@ -67,5 +67,4 @@ void main() { test('Can instantiate IMoniker.isSystemMoniker', () { expect(moniker.isSystemMoniker, isA()); }); - free(ptr); } diff --git a/test/com/inetwork_test.dart b/test/com/inetwork_test.dart index b2d058d519..655e689f42 100644 --- a/test/com/inetwork_test.dart +++ b/test/com/inetwork_test.dart @@ -55,5 +55,4 @@ void main() { test('Can instantiate INetwork.setCategory', () { expect(network.setCategory, isA()); }); - free(ptr); } diff --git a/test/com/inetworkconnection_test.dart b/test/com/inetworkconnection_test.dart index 7c793fc861..600934df3f 100644 --- a/test/com/inetworkconnection_test.dart +++ b/test/com/inetworkconnection_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate INetworkConnection.getDomainType', () { expect(networkconnection.getDomainType, isA()); }); - free(ptr); } diff --git a/test/com/inetworklistmanager_test.dart b/test/com/inetworklistmanager_test.dart index 83a9622671..874e43fc28 100644 --- a/test/com/inetworklistmanager_test.dart +++ b/test/com/inetworklistmanager_test.dart @@ -43,5 +43,4 @@ void main() { test('Can instantiate INetworkListManager.clearSimulatedProfileInfo', () { expect(networklistmanager.clearSimulatedProfileInfo, isA()); }); - free(ptr); } diff --git a/test/com/inetworklistmanagerevents_test.dart b/test/com/inetworklistmanagerevents_test.dart index 43b9ab613c..4dffc5b421 100644 --- a/test/com/inetworklistmanagerevents_test.dart +++ b/test/com/inetworklistmanagerevents_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate INetworkListManagerEvents.connectivityChanged', () { expect(networklistmanagerevents.connectivityChanged, isA()); }); - free(ptr); } diff --git a/test/com/ipersist_test.dart b/test/com/ipersist_test.dart index 8254801397..a01fe69f25 100644 --- a/test/com/ipersist_test.dart +++ b/test/com/ipersist_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IPersist.getClassID', () { expect(persist.getClassID, isA()); }); - free(ptr); } diff --git a/test/com/ipersistfile_test.dart b/test/com/ipersistfile_test.dart index eb07c357a7..f948c4b1ce 100644 --- a/test/com/ipersistfile_test.dart +++ b/test/com/ipersistfile_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IPersistFile.getCurFile', () { expect(persistfile.getCurFile, isA()); }); - free(ptr); } diff --git a/test/com/ipersistmemory_test.dart b/test/com/ipersistmemory_test.dart index 4bc2f7c409..f197933816 100644 --- a/test/com/ipersistmemory_test.dart +++ b/test/com/ipersistmemory_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IPersistMemory.initNew', () { expect(persistmemory.initNew, isA()); }); - free(ptr); } diff --git a/test/com/ipersiststream_test.dart b/test/com/ipersiststream_test.dart index 9ba5b9bbf3..039425f43c 100644 --- a/test/com/ipersiststream_test.dart +++ b/test/com/ipersiststream_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IPersistStream.getSizeMax', () { expect(persiststream.getSizeMax, isA()); }); - free(ptr); } diff --git a/test/com/iprovideclassinfo_test.dart b/test/com/iprovideclassinfo_test.dart index 628f275cff..62354ce068 100644 --- a/test/com/iprovideclassinfo_test.dart +++ b/test/com/iprovideclassinfo_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IProvideClassInfo.getClassInfo', () { expect(provideclassinfo.getClassInfo, isA()); }); - free(ptr); } diff --git a/test/com/irunningobjecttable_test.dart b/test/com/irunningobjecttable_test.dart index 35e2a7c156..d85cb26384 100644 --- a/test/com/irunningobjecttable_test.dart +++ b/test/com/irunningobjecttable_test.dart @@ -43,5 +43,4 @@ void main() { test('Can instantiate IRunningObjectTable.enumRunning', () { expect(runningobjecttable.enumRunning, isA()); }); - free(ptr); } diff --git a/test/com/isensor_test.dart b/test/com/isensor_test.dart index 5d20db869c..2c69b76719 100644 --- a/test/com/isensor_test.dart +++ b/test/com/isensor_test.dart @@ -67,5 +67,4 @@ void main() { test('Can instantiate ISensor.setEventSink', () { expect(sensor.setEventSink, isA()); }); - free(ptr); } diff --git a/test/com/isensorcollection_test.dart b/test/com/isensorcollection_test.dart index c641e1d0c5..aed46876f1 100644 --- a/test/com/isensorcollection_test.dart +++ b/test/com/isensorcollection_test.dart @@ -40,5 +40,4 @@ void main() { test('Can instantiate ISensorCollection.clear', () { expect(sensorcollection.clear, isA()); }); - free(ptr); } diff --git a/test/com/isensordatareport_test.dart b/test/com/isensordatareport_test.dart index fc0e9a8657..1d1c083641 100644 --- a/test/com/isensordatareport_test.dart +++ b/test/com/isensordatareport_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate ISensorDataReport.getSensorValues', () { expect(sensordatareport.getSensorValues, isA()); }); - free(ptr); } diff --git a/test/com/isensormanager_test.dart b/test/com/isensormanager_test.dart index a961c34b4a..1e9b3019ee 100644 --- a/test/com/isensormanager_test.dart +++ b/test/com/isensormanager_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate ISensorManager.requestPermissions', () { expect(sensormanager.requestPermissions, isA()); }); - free(ptr); } diff --git a/test/com/isequentialstream_test.dart b/test/com/isequentialstream_test.dart index f3d98ce2a3..db2fb8e576 100644 --- a/test/com/isequentialstream_test.dart +++ b/test/com/isequentialstream_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate ISequentialStream.write', () { expect(sequentialstream.write, isA()); }); - free(ptr); } diff --git a/test/com/ishellfolder_test.dart b/test/com/ishellfolder_test.dart index 62f00c1c91..450b20b7af 100644 --- a/test/com/ishellfolder_test.dart +++ b/test/com/ishellfolder_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate IShellFolder.setNameOf', () { expect(shellfolder.setNameOf, isA()); }); - free(ptr); } diff --git a/test/com/ishellitem2_test.dart b/test/com/ishellitem2_test.dart index f80e69b7c1..b907d66253 100644 --- a/test/com/ishellitem2_test.dart +++ b/test/com/ishellitem2_test.dart @@ -61,5 +61,4 @@ void main() { test('Can instantiate IShellItem2.getBool', () { expect(shellitem2.getBool, isA()); }); - free(ptr); } diff --git a/test/com/ishellitem_test.dart b/test/com/ishellitem_test.dart index e42da23379..7c848924c6 100644 --- a/test/com/ishellitem_test.dart +++ b/test/com/ishellitem_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IShellItem.compare', () { expect(shellitem.compare, isA()); }); - free(ptr); } diff --git a/test/com/ishellitemarray_test.dart b/test/com/ishellitemarray_test.dart index c2b8e7c6b7..b0a9608127 100644 --- a/test/com/ishellitemarray_test.dart +++ b/test/com/ishellitemarray_test.dart @@ -43,5 +43,4 @@ void main() { test('Can instantiate IShellItemArray.enumItems', () { expect(shellitemarray.enumItems, isA()); }); - free(ptr); } diff --git a/test/com/ishellitemfilter_test.dart b/test/com/ishellitemfilter_test.dart index 5f717ae041..928bb95844 100644 --- a/test/com/ishellitemfilter_test.dart +++ b/test/com/ishellitemfilter_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate IShellItemFilter.getEnumFlagsForItem', () { expect(shellitemfilter.getEnumFlagsForItem, isA()); }); - free(ptr); } diff --git a/test/com/ishellitemimagefactory_test.dart b/test/com/ishellitemimagefactory_test.dart index a9574dd345..342498965a 100644 --- a/test/com/ishellitemimagefactory_test.dart +++ b/test/com/ishellitemimagefactory_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IShellItemImageFactory.getImage', () { expect(shellitemimagefactory.getImage, isA()); }); - free(ptr); } diff --git a/test/com/ishellitemresources_test.dart b/test/com/ishellitemresources_test.dart index 2a409282f5..c27898e195 100644 --- a/test/com/ishellitemresources_test.dart +++ b/test/com/ishellitemresources_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate IShellItemResources.markForDelete', () { expect(shellitemresources.markForDelete, isA()); }); - free(ptr); } diff --git a/test/com/ishelllink_test.dart b/test/com/ishelllink_test.dart index e6bc652291..a27a92fd47 100644 --- a/test/com/ishelllink_test.dart +++ b/test/com/ishelllink_test.dart @@ -76,5 +76,4 @@ void main() { test('Can instantiate IShellLink.setPath', () { expect(shelllink.setPath, isA()); }); - free(ptr); } diff --git a/test/com/ishelllinkdatalist_test.dart b/test/com/ishelllinkdatalist_test.dart index 09ac429d18..ed7276c58c 100644 --- a/test/com/ishelllinkdatalist_test.dart +++ b/test/com/ishelllinkdatalist_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IShellLinkDataList.setFlags', () { expect(shelllinkdatalist.setFlags, isA()); }); - free(ptr); } diff --git a/test/com/ishelllinkdual_test.dart b/test/com/ishelllinkdual_test.dart index 673cd5a223..ca548367ef 100644 --- a/test/com/ishelllinkdual_test.dart +++ b/test/com/ishelllinkdual_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IShellLinkDual.save', () { expect(shelllinkdual.save, isA()); }); - free(ptr); } diff --git a/test/com/ishellservice_test.dart b/test/com/ishellservice_test.dart index 44fd82da3f..e2de686e2a 100644 --- a/test/com/ishellservice_test.dart +++ b/test/com/ishellservice_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IShellService.setOwner', () { expect(shellservice.setOwner, isA()); }); - free(ptr); } diff --git a/test/com/isimpleaudiovolume_test.dart b/test/com/isimpleaudiovolume_test.dart index 159b93b133..f048eee5ca 100644 --- a/test/com/isimpleaudiovolume_test.dart +++ b/test/com/isimpleaudiovolume_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate ISimpleAudioVolume.getMute', () { expect(simpleaudiovolume.getMute, isA()); }); - free(ptr); } diff --git a/test/com/ispeechobjecttoken_test.dart b/test/com/ispeechobjecttoken_test.dart index a8a8b6f55a..9c0a172c1c 100644 --- a/test/com/ispeechobjecttoken_test.dart +++ b/test/com/ispeechobjecttoken_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate ISpeechObjectToken.matchesAttributes', () { expect(speechobjecttoken.matchesAttributes, isA()); }); - free(ptr); } diff --git a/test/com/ispeechobjecttokens_test.dart b/test/com/ispeechobjecttokens_test.dart index 50ab385922..0817d70bd8 100644 --- a/test/com/ispeechobjecttokens_test.dart +++ b/test/com/ispeechobjecttokens_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate ISpeechObjectTokens.item', () { expect(speechobjecttokens.item, isA()); }); - free(ptr); } diff --git a/test/com/ispellchecker2_test.dart b/test/com/ispellchecker2_test.dart index 77d990eb48..ad4e8bb855 100644 --- a/test/com/ispellchecker2_test.dart +++ b/test/com/ispellchecker2_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate ISpellChecker2.remove', () { expect(spellchecker2.remove, isA()); }); - free(ptr); } diff --git a/test/com/ispellchecker_test.dart b/test/com/ispellchecker_test.dart index 3b84571dc9..bf1d654e3d 100644 --- a/test/com/ispellchecker_test.dart +++ b/test/com/ispellchecker_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate ISpellChecker.comprehensiveCheck', () { expect(spellchecker.comprehensiveCheck, isA()); }); - free(ptr); } diff --git a/test/com/ispellcheckerchangedeventhandler_test.dart b/test/com/ispellcheckerchangedeventhandler_test.dart index 875b384c22..91f8568f73 100644 --- a/test/com/ispellcheckerchangedeventhandler_test.dart +++ b/test/com/ispellcheckerchangedeventhandler_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate ISpellCheckerChangedEventHandler.invoke', () { expect(spellcheckerchangedeventhandler.invoke, isA()); }); - free(ptr); } diff --git a/test/com/ispellcheckerfactory_test.dart b/test/com/ispellcheckerfactory_test.dart index 05cf6fe571..c31ac4a75e 100644 --- a/test/com/ispellcheckerfactory_test.dart +++ b/test/com/ispellcheckerfactory_test.dart @@ -28,5 +28,4 @@ void main() { test('Can instantiate ISpellCheckerFactory.createSpellChecker', () { expect(spellcheckerfactory.createSpellChecker, isA()); }); - free(ptr); } diff --git a/test/com/ispellingerror_test.dart b/test/com/ispellingerror_test.dart index 17f2c02e33..429914f620 100644 --- a/test/com/ispellingerror_test.dart +++ b/test/com/ispellingerror_test.dart @@ -22,6 +22,4 @@ void main() { final ptr = calloc(); final spellingerror = ISpellingError(ptr); - - free(ptr); } diff --git a/test/com/ispeventsource_test.dart b/test/com/ispeventsource_test.dart index 619c2ecd11..50f1b2f701 100644 --- a/test/com/ispeventsource_test.dart +++ b/test/com/ispeventsource_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate ISpEventSource.getInfo', () { expect(speventsource.getInfo, isA()); }); - free(ptr); } diff --git a/test/com/ispnotifysource_test.dart b/test/com/ispnotifysource_test.dart index 628d63032a..677377e2ff 100644 --- a/test/com/ispnotifysource_test.dart +++ b/test/com/ispnotifysource_test.dart @@ -43,5 +43,4 @@ void main() { test('Can instantiate ISpNotifySource.getNotifyEventHandle', () { expect(spnotifysource.getNotifyEventHandle, isA()); }); - free(ptr); } diff --git a/test/com/ispvoice_test.dart b/test/com/ispvoice_test.dart index 0910d80501..4c56cf03a5 100644 --- a/test/com/ispvoice_test.dart +++ b/test/com/ispvoice_test.dart @@ -97,5 +97,4 @@ void main() { test('Can instantiate ISpVoice.displayUI', () { expect(spvoice.displayUI, isA()); }); - free(ptr); } diff --git a/test/com/istream_test.dart b/test/com/istream_test.dart index b064977be3..5dd8b6fdac 100644 --- a/test/com/istream_test.dart +++ b/test/com/istream_test.dart @@ -49,5 +49,4 @@ void main() { test('Can instantiate IStream.clone', () { expect(stream.clone, isA()); }); - free(ptr); } diff --git a/test/com/isupporterrorinfo_test.dart b/test/com/isupporterrorinfo_test.dart index 8ba9669003..2a43951273 100644 --- a/test/com/isupporterrorinfo_test.dart +++ b/test/com/isupporterrorinfo_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate ISupportErrorInfo.interfaceSupportsErrorInfo', () { expect(supporterrorinfo.interfaceSupportsErrorInfo, isA()); }); - free(ptr); } diff --git a/test/com/itypeinfo_test.dart b/test/com/itypeinfo_test.dart index 3cfd3a7508..43f769573f 100644 --- a/test/com/itypeinfo_test.dart +++ b/test/com/itypeinfo_test.dart @@ -79,5 +79,4 @@ void main() { test('Can instantiate ITypeInfo.releaseVarDesc', () { expect(typeinfo.releaseVarDesc, isA()); }); - free(ptr); } diff --git a/test/com/iunknown_test.dart b/test/com/iunknown_test.dart index 3bea616f7a..6cf26b8767 100644 --- a/test/com/iunknown_test.dart +++ b/test/com/iunknown_test.dart @@ -31,5 +31,4 @@ void main() { test('Can instantiate IUnknown.release', () { expect(unknown.release, isA()); }); - free(ptr); } diff --git a/test/com/iuri_test.dart b/test/com/iuri_test.dart index 9a374da25e..42cbdd5f50 100644 --- a/test/com/iuri_test.dart +++ b/test/com/iuri_test.dart @@ -97,5 +97,4 @@ void main() { test('Can instantiate IUri.isEqual', () { expect(uri.isEqual, isA()); }); - free(ptr); } diff --git a/test/com/ivirtualdesktopmanager_test.dart b/test/com/ivirtualdesktopmanager_test.dart index d4e9355e4e..002cbdaa27 100644 --- a/test/com/ivirtualdesktopmanager_test.dart +++ b/test/com/ivirtualdesktopmanager_test.dart @@ -33,5 +33,4 @@ void main() { test('Can instantiate IVirtualDesktopManager.moveWindowToDesktop', () { expect(virtualdesktopmanager.moveWindowToDesktop, isA()); }); - free(ptr); } diff --git a/test/com/iwbemclassobject_test.dart b/test/com/iwbemclassobject_test.dart index 21d22a2e5f..88df092a7c 100644 --- a/test/com/iwbemclassobject_test.dart +++ b/test/com/iwbemclassobject_test.dart @@ -94,5 +94,4 @@ void main() { test('Can instantiate IWbemClassObject.getMethodOrigin', () { expect(wbemclassobject.getMethodOrigin, isA()); }); - free(ptr); } diff --git a/test/com/iwbemconfigurerefresher_test.dart b/test/com/iwbemconfigurerefresher_test.dart index 76f37720a0..7698ea02a0 100644 --- a/test/com/iwbemconfigurerefresher_test.dart +++ b/test/com/iwbemconfigurerefresher_test.dart @@ -37,5 +37,4 @@ void main() { test('Can instantiate IWbemConfigureRefresher.addEnum', () { expect(wbemconfigurerefresher.addEnum, isA()); }); - free(ptr); } diff --git a/test/com/iwbemcontext_test.dart b/test/com/iwbemcontext_test.dart index 1290d68d52..1bec93a45e 100644 --- a/test/com/iwbemcontext_test.dart +++ b/test/com/iwbemcontext_test.dart @@ -49,5 +49,4 @@ void main() { test('Can instantiate IWbemContext.deleteAll', () { expect(wbemcontext.deleteAll, isA()); }); - free(ptr); } diff --git a/test/com/iwbemhiperfenum_test.dart b/test/com/iwbemhiperfenum_test.dart index 6b7039026f..89a868c626 100644 --- a/test/com/iwbemhiperfenum_test.dart +++ b/test/com/iwbemhiperfenum_test.dart @@ -34,5 +34,4 @@ void main() { test('Can instantiate IWbemHiPerfEnum.removeAll', () { expect(wbemhiperfenum.removeAll, isA()); }); - free(ptr); } diff --git a/test/com/iwbemlocator_test.dart b/test/com/iwbemlocator_test.dart index a83207c14e..e989b54169 100644 --- a/test/com/iwbemlocator_test.dart +++ b/test/com/iwbemlocator_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IWbemLocator.connectServer', () { expect(wbemlocator.connectServer, isA()); }); - free(ptr); } diff --git a/test/com/iwbemobjectaccess_test.dart b/test/com/iwbemobjectaccess_test.dart index 876ea692d4..6aad9331fc 100644 --- a/test/com/iwbemobjectaccess_test.dart +++ b/test/com/iwbemobjectaccess_test.dart @@ -52,5 +52,4 @@ void main() { test('Can instantiate IWbemObjectAccess.unlock', () { expect(wbemobjectaccess.unlock, isA()); }); - free(ptr); } diff --git a/test/com/iwbemrefresher_test.dart b/test/com/iwbemrefresher_test.dart index 799abb4721..a4eb5aeafd 100644 --- a/test/com/iwbemrefresher_test.dart +++ b/test/com/iwbemrefresher_test.dart @@ -25,5 +25,4 @@ void main() { test('Can instantiate IWbemRefresher.refresh', () { expect(wbemrefresher.refresh, isA()); }); - free(ptr); } diff --git a/test/com/iwbemservices_test.dart b/test/com/iwbemservices_test.dart index 0ea2dc2f8d..907d1b26fa 100644 --- a/test/com/iwbemservices_test.dart +++ b/test/com/iwbemservices_test.dart @@ -91,5 +91,4 @@ void main() { test('Can instantiate IWbemServices.execMethodAsync', () { expect(wbemservices.execMethodAsync, isA()); }); - free(ptr); } diff --git a/tool/generator/lib/src/projection/test_interface.dart b/tool/generator/lib/src/projection/test_interface.dart index 3b7b0bd002..8ad37630a6 100644 --- a/tool/generator/lib/src/projection/test_interface.dart +++ b/tool/generator/lib/src/projection/test_interface.dart @@ -64,7 +64,6 @@ void main() { final $instanceName = $interfaceName(ptr); ${projection.methodProjections.map((p) => testMethod(interfaceName, instanceName, p)).join()} - free(ptr); } """; } From 4758f1f92364a09d8022fef7c4425c25f0d412cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:51:00 +0300 Subject: [PATCH 05/17] Update `com.md` --- doc/com.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/com.md b/doc/com.md index a3a817ccfb..4ade91c003 100644 --- a/doc/com.md +++ b/doc/com.md @@ -41,9 +41,7 @@ final fileDialog2 = IFileDialog2( ``` `createFromID` returns a `Pointer` containing the requested object, -which can then be cast into the appropriate interface as shown above. It is the -caller's responsibility to free the returned pointer when all interfaces that -derive from it are released. +which can then be cast into the appropriate interface as shown above. ### Asking a COM object for an interface @@ -60,14 +58,18 @@ documentation](https://docs.microsoft.com/en-us/windows/win32/learnwin32/asking- COM interfaces supply a method that wraps `queryInterface`. If you have an existing COM object, you can call it as follows: +```dart + final modalWindow = IModalWindow(fileDialog2.toInterface(IID_IModalWindow)); +``` + +or, you can use the `from` constructor that wraps the `toInterface` for you: + ```dart final modalWindow = IModalWindow.from(fileDialog2); ``` Where `createFromID` creates a new COM object, `toInterface` casts an existing -COM object to a new interface. As with `createFromID`, it is the caller's -responsibility to free the returned pointer when all interfaces that derive from -it are released. +COM object to a new interface. Attempting to cast a COM object to an interface it does not support will fail, of course. A `WindowsException` will be thrown with an hr of `E_NOINTERFACE`. @@ -102,7 +104,6 @@ When you have finished using a COM interface, you should release it with the `re ```dart fileOpenDialog.release(); // Release the interface -free(fileOpenDialog.ptr); // Release the pointer to the interface ``` Often this will be called as part of a `try` / `finally` block, to guarantee From 23cf44f7d34fd6cf89a58ac136508562b3c6dee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:51:22 +0300 Subject: [PATCH 06/17] Fix examples --- example/calendar.dart | 4 ++-- example/com_demo.dart | 7 ++----- example/knownfolder.dart | 15 +++++++-------- example/network.dart | 21 +++++++-------------- example/shortcut.dart | 14 ++++---------- example/speech.dart | 4 ++++ example/wasapi.dart | 4 ---- example/winrt_picker.dart | 3 ++- example/wmi_perf.dart | 6 ++---- 9 files changed, 30 insertions(+), 48 deletions(-) diff --git a/example/calendar.dart b/example/calendar.dart index 43f9e0ccf1..ef841b57af 100644 --- a/example/calendar.dart +++ b/example/calendar.dart @@ -36,8 +36,8 @@ void main() { final dateTime = calendar.getDateTime(); print(dateTime); - free(calendar.ptr); - free(clonedCalendar.ptr); + clonedCalendar.release(); + calendar.release(); } finally { winrtUninitialize(); } diff --git a/example/com_demo.dart b/example/com_demo.dart index fbde0b643b..b1e42fd7eb 100644 --- a/example/com_demo.dart +++ b/example/com_demo.dart @@ -10,7 +10,7 @@ import 'package:win32/win32.dart'; /// Return the current reference count. int refCount(IUnknown unk) { - // Call AddRef() and Release(), which are inherited from IUnknown. Both return + // Call addRef() and release(), which are inherited from IUnknown. Both return // the refcount after the operation, so by adding a reference and immediately // removing it, we can get the original refcount. @@ -52,7 +52,6 @@ void main() { print('refCount is now ${refCount(modalWindow)}\n'); fileDialog2.release(); - free(fileDialog2.ptr); print('Release fileDialog2.\n' 'refCount is now ${refCount(modalWindow)}\n'); @@ -64,7 +63,6 @@ void main() { print('refCount is now ${refCount(fileOpenDialog)}\n'); modalWindow.release(); - free(modalWindow.ptr); print('Release modalWindow.\n' 'refCount is now ${refCount(fileOpenDialog)}\n'); @@ -79,10 +77,9 @@ void main() { } fileOpenDialog.release(); - free(fileOpenDialog.ptr); print('Released fileOpenDialog.'); - free(fileDialog.ptr); + fileDialog.release(); print('Released fileDialog.'); // Uninitialize COM now that we're done with it. diff --git a/example/knownfolder.dart b/example/knownfolder.dart index fd4c1effc1..66264273c6 100644 --- a/example/knownfolder.dart +++ b/example/knownfolder.dart @@ -5,6 +5,7 @@ // Demonstrates usage of various shell APIs to retrieve known folder locations import 'dart:ffi'; + import 'package:ffi/ffi.dart'; import 'package:win32/win32.dart'; @@ -81,23 +82,21 @@ String getDesktopPath3() { try { final knownFolderManager = KnownFolderManager.createInstance(); var hr = knownFolderManager.getFolder(appsFolder, ppkf.cast()); - if (FAILED(hr)) { - throw WindowsException(hr); - } + if (FAILED(hr)) throw WindowsException(hr); final knownFolder = IKnownFolder(ppkf); hr = knownFolder.getPath(0, ppszPath); - if (FAILED(hr)) { - throw WindowsException(hr); - } + if (FAILED(hr)) throw WindowsException(hr); + + knownFolder.release(); + knownFolderManager.release(); final path = ppszPath.value.toDartString(); - CoUninitialize(); return path; } finally { free(appsFolder); - free(ppkf); free(ppszPath); + CoUninitialize(); } } diff --git a/example/network.dart b/example/network.dart index 6a9539e01c..a768a8efe6 100644 --- a/example/network.dart +++ b/example/network.dart @@ -12,22 +12,16 @@ import 'package:win32/win32.dart'; void main() { // Initialize COM var hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); - if (FAILED(hr)) { - throw WindowsException(hr); - } + if (FAILED(hr)) throw WindowsException(hr); final netManager = NetworkListManager.createInstance(); final nlmConnectivity = calloc(); - final enumPtr = calloc(); - final netPtr = calloc(); final descPtr = calloc>(); final elements = calloc(); try { hr = netManager.getConnectivity(nlmConnectivity); - if (FAILED(hr)) { - throw WindowsException(hr); - } + if (FAILED(hr)) throw WindowsException(hr); final connectivity = nlmConnectivity.value; var isInternetConnected = false; @@ -49,14 +43,14 @@ void main() { print('Not connected to the Internet.'); } + final enumPtr = calloc(); hr = netManager.getNetworks( NLM_ENUM_NETWORK.NLM_ENUM_NETWORK_ALL, enumPtr.cast()); - if (FAILED(hr)) { - throw WindowsException(hr); - } + if (FAILED(hr)) throw WindowsException(hr); print('\nNetworks (connected and disconnected) on this machine:'); final enumerator = IEnumNetworkConnections(enumPtr); + var netPtr = calloc(); hr = enumerator.next(1, netPtr.cast(), elements); while (elements.value == 1) { final network = INetwork(netPtr); @@ -68,15 +62,14 @@ void main() { '$networkName: ${isNetworkConnected ? 'connected' : 'disconnected'}'); } + netPtr = calloc(); hr = enumerator.next(1, netPtr.cast(), elements); } } finally { free(elements); - free(netPtr); - free(enumPtr); free(descPtr); free(nlmConnectivity); - free(netManager.ptr); + netManager.release(); CoUninitialize(); } diff --git a/example/shortcut.dart b/example/shortcut.dart index 59524d6f1f..4f78788897 100644 --- a/example/shortcut.dart +++ b/example/shortcut.dart @@ -17,26 +17,20 @@ void createShortcut(String path, String pathLink, String? description) { final lpPath = path.toNativeUtf16(); final lpPathLink = pathLink.toNativeUtf16(); final lpDescription = description?.toNativeUtf16() ?? nullptr; - final ptrIID_IPersistFile = convertToCLSID(IID_IPersistFile); - final ppf = calloc(); try { shellLink.setPath(lpPath); if (description != null) shellLink.setDescription(lpDescription); - final hr = shellLink.queryInterface(ptrIID_IPersistFile, ppf.cast()); - if (SUCCEEDED(hr)) { - IPersistFile(ppf) - ..save(lpPathLink, TRUE) - ..release(); - } + final persistFile = IPersistFile.from(shellLink); shellLink.release(); + persistFile + ..save(lpPathLink, TRUE) + ..release(); } finally { free(lpPath); free(lpPathLink); if (lpDescription != nullptr) free(lpDescription); - free(ptrIID_IPersistFile); - free(ppf); } } diff --git a/example/speech.dart b/example/speech.dart index 396a87b067..d7dc106600 100644 --- a/example/speech.dart +++ b/example/speech.dart @@ -14,9 +14,13 @@ const textToSpeak = void main() { CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + final speechEngine = SpVoice.createInstance(); final pText = textToSpeak.toNativeUtf16(); speechEngine.speak(pText, SPEAKFLAGS.SPF_IS_NOT_XML, nullptr); + free(pText); + speechEngine.release(); + CoUninitialize(); } diff --git a/example/wasapi.dart b/example/wasapi.dart index 75e125bfe3..d08e9c5e22 100644 --- a/example/wasapi.dart +++ b/example/wasapi.dart @@ -91,7 +91,6 @@ void main() { 0, // role: system notification sound ppDevice)); pDeviceEnumerator.release(); - free(pDeviceEnumerator.ptr); // Activate an IAudioClient interface for the output device. final pDevice = IMMDevice(ppDevice.cast()); @@ -164,13 +163,10 @@ void main() { free(pData); pDevice.release(); - free(ppDevice); pAudioClient.release(); - free(ppAudioClient); pAudioRenderClient.release(); - free(ppAudioRenderClient); free(ppFormat); diff --git a/example/winrt_picker.dart b/example/winrt_picker.dart index 317c977068..cf8439e986 100644 --- a/example/winrt_picker.dart +++ b/example/winrt_picker.dart @@ -69,6 +69,7 @@ void main() async { print('Vector has ${filters.size} elements.'); free(pIndex); - free(filters.ptr); + filters.release(); + picker.release(); winrtUninitialize(); } diff --git a/example/wmi_perf.dart b/example/wmi_perf.dart index ac1af9e3ad..1c96ee9e07 100644 --- a/example/wmi_perf.dart +++ b/example/wmi_perf.dart @@ -67,13 +67,13 @@ void main() { using((Arena arena) { final pLoc = WbemLocator.createInstance(); - final ppNamespace = arena>(); + final ppNamespace = calloc>(); connectWMI(pLoc, ppNamespace); final refresher = WbemRefresher.createInstance(); final pConfig = IWbemConfigureRefresher.from(refresher); - final ppRefreshable = arena>(); + final ppRefreshable = calloc>(); final pszQuery = 'Win32_PerfRawData_PerfProc_Process.Name="$processToMonitor"' @@ -111,10 +111,8 @@ void main() { refresher.release(); pConfig.release(); - free(refresher.ptr); pLoc.release(); - free(pLoc.ptr); CoUninitialize(); }); From 0a1e1d7df2420d1829de0078fd684de51e836f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:51:37 +0300 Subject: [PATCH 07/17] Update winrt library documentation --- lib/winrt.dart | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/winrt.dart b/lib/winrt.dart index 6eaa46b011..25cc8e419f 100644 --- a/lib/winrt.dart +++ b/lib/winrt.dart @@ -37,28 +37,12 @@ /// final calendar = ICalendar.fromRawPointer(comObject); /// ``` /// -/// The object should be disposed of when it is no longer in use, for example: +/// When you have finished using a Windows Runtime interface, you should release +/// it with the `release` method: /// /// ```dart -/// free(calendar.ptr); +/// calendar.release(); // Release the interface /// ``` -/// -/// ## Strings in the Windows Runtime -/// -/// Windows Runtime APIs use `HSTRING` as their native type. An `HSTRING` is an -/// immutable string object, which is created with the [WindowsCreateString] API -/// and deleted with the [WindowsDeleteString] API. The `HSTRING` itself is an -/// integer value, just like other `HANDLE` objects in the Win32 programming -/// interface. -/// -/// Helper functions exist to easily convert between the Dart `String` type and -/// Windows Runtime strings: specifically, [convertToHString] and -/// [convertFromHString]. -/// -/// Make sure you dispose of `HSTRING`s by calling `WindowsDeleteString`; you do -/// not need to free the pointer itself, since Windows reference counts the -/// backing store and frees the memory when the reference count reaches 0. - library winrt; // The WinRT API builds on the underlying Win32 API, and so it is also exported From 917f3ef22bbd03f1526fdd1912b737b65b8b756c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:52:21 +0300 Subject: [PATCH 08/17] Update toMap helper function --- lib/src/winrt/internal/map_helpers.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/winrt/internal/map_helpers.dart b/lib/src/winrt/internal/map_helpers.dart index 727b33f968..f4402baa62 100644 --- a/lib/src/winrt/internal/map_helpers.dart +++ b/lib/src/winrt/internal/map_helpers.dart @@ -32,10 +32,14 @@ class MapHelper { final map = Map.fromEntries( keyValuePairs.map((kvp) => MapEntry(kvp.key, kvp.value))); + for (final kvp in keyValuePairs) { + kvp.release(); + } + return Map.unmodifiable(map); } finally { + iterator.release(); free(pKeyValuePairArray); - free(iterator.ptr); } } } From 5eb8e243187a0533881ef0480e8e31674dbdf6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:52:47 +0300 Subject: [PATCH 09/17] Update WinRT collection interfaces --- .../foundation/collections/iiterator.dart | 32 ++++--- .../foundation/collections/ikeyvaluepair.dart | 2 + .../winrt/foundation/collections/imap.dart | 88 +++++++++-------- .../foundation/collections/imapview.dart | 6 ++ .../winrt/foundation/collections/ivector.dart | 94 ++++++++++--------- .../foundation/collections/ivectorview.dart | 37 ++++---- 6 files changed, 134 insertions(+), 125 deletions(-) diff --git a/lib/src/winrt/foundation/collections/iiterator.dart b/lib/src/winrt/foundation/collections/iiterator.dart index 65510823b9..50087b5458 100644 --- a/lib/src/winrt/foundation/collections/iiterator.dart +++ b/lib/src/winrt/foundation/collections/iiterator.dart @@ -313,24 +313,26 @@ class IIterator extends IInspectable { Uri _current_Uri() { final retValuePtr = calloc(); - try { - final hr = ptr.ref.lpVtbl.value - .elementAt(6) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); + final hr = ptr.ref.lpVtbl.value + .elementAt(6) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); - return Uri.parse(winrtUri.toString()); - } finally { + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); + final uriAsString = winrtUri.toString(); + winrtUri.release(); + + return Uri.parse(uriAsString); } /// Gets a value that indicates whether the iterator refers to a current item diff --git a/lib/src/winrt/foundation/collections/ikeyvaluepair.dart b/lib/src/winrt/foundation/collections/ikeyvaluepair.dart index aed38e24cd..3c2fbd9c9a 100644 --- a/lib/src/winrt/foundation/collections/ikeyvaluepair.dart +++ b/lib/src/winrt/foundation/collections/ikeyvaluepair.dart @@ -243,6 +243,8 @@ class IKeyValuePair extends IInspectable { throw WindowsException(hr); } + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } diff --git a/lib/src/winrt/foundation/collections/imap.dart b/lib/src/winrt/foundation/collections/imap.dart index 387c25653a..98025dcae8 100644 --- a/lib/src/winrt/foundation/collections/imap.dart +++ b/lib/src/winrt/foundation/collections/imap.dart @@ -48,18 +48,30 @@ class IMap extends IInspectable /// `Object?` or `String`. factory IMap() { if (isSameType() && isSimilarType()) { - return IMap.fromRawPointer(MediaPropertySet().ptr, + final mediaPropertySet = MediaPropertySet(); + final mapPtr = mediaPropertySet.toInterface(IID_IMap_Guid_Object); + mediaPropertySet.release(); + + return IMap.fromRawPointer(mapPtr, iterableIid: IID_IIterable_IKeyValuePair_Guid_Object); } if (isSameType()) { if (isSameType()) { - return IMap.fromRawPointer(StringMap().ptr, + final stringMap = StringMap(); + final mapPtr = stringMap.toInterface(IID_IMap_String_String); + stringMap.release(); + + return IMap.fromRawPointer(mapPtr, iterableIid: IID_IIterable_IKeyValuePair_String_String); } if (isSimilarType()) { - return IMap.fromRawPointer(PropertySet().ptr, + final propertySet = PropertySet(); + final mapPtr = propertySet.toInterface(IID_IMap_String_Object); + propertySet.release(); + + return IMap.fromRawPointer(mapPtr, iterableIid: IID_IIterable_IKeyValuePair_String_Object); } } @@ -120,30 +132,9 @@ class IMap extends IInspectable /// [other] must be of type `Map`, `Map`, /// or `Map`. factory IMap.fromMap(Map other) { - if (isSameType() && isSimilarType()) { - final iMap = MediaPropertySet(); - other.cast().forEach(iMap.insert); - return IMap.fromRawPointer(iMap.ptr, - iterableIid: IID_IIterable_IKeyValuePair_Guid_Object); - } - - if (isSameType()) { - if (isSameType()) { - final iMap = StringMap(); - other.cast().forEach(iMap.insert); - return IMap.fromRawPointer(iMap.ptr, - iterableIid: IID_IIterable_IKeyValuePair_String_String); - } - - if (isSimilarType()) { - final iMap = PropertySet(); - other.cast().forEach(iMap.insert); - return IMap.fromRawPointer(iMap.ptr, - iterableIid: IID_IIterable_IKeyValuePair_String_Object); - } - } - - throw ArgumentError.value(other, 'other', 'Unsupported map'); + final map = IMap(); + other.forEach(map.insert); + return map; } /// Returns the item at the specified key in the map. @@ -230,6 +221,8 @@ class IMap extends IInspectable free(nativeGuidPtr); + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } @@ -275,6 +268,8 @@ class IMap extends IInspectable throw WindowsException(hr); } + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } @@ -352,6 +347,8 @@ class IMap extends IInspectable throw WindowsException(hr); } + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } finally { WindowsDeleteString(hKey); @@ -518,27 +515,26 @@ class IMap extends IInspectable Map getView() { final retValuePtr = calloc(); - try { - final hr = ptr.ref.lpVtbl.value - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); + final hr = ptr.ref.lpVtbl.value + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); + if (FAILED(hr)) throw WindowsException(hr); - return IMapView.fromRawPointer(retValuePtr, - creator: _creator, - enumCreator: _enumCreator, - iterableIid: _iterableIid) - .toMap(); - } finally { - free(retValuePtr); - } + final mapView = IMapView.fromRawPointer(retValuePtr, + creator: _creator, + enumCreator: _enumCreator, + iterableIid: _iterableIid); + final map = mapView.toMap(); + mapView.release(); + + return map; } /// Inserts or replaces an item in the map. diff --git a/lib/src/winrt/foundation/collections/imapview.dart b/lib/src/winrt/foundation/collections/imapview.dart index e37694aabb..b3879ef3a0 100644 --- a/lib/src/winrt/foundation/collections/imapview.dart +++ b/lib/src/winrt/foundation/collections/imapview.dart @@ -168,6 +168,8 @@ class IMapView extends IInspectable free(nativeGuidPtr); + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } @@ -213,6 +215,8 @@ class IMapView extends IInspectable throw WindowsException(hr); } + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } @@ -290,6 +294,8 @@ class IMapView extends IInspectable throw WindowsException(hr); } + if (retValuePtr.ref.lpVtbl == nullptr) return null; + return IPropertyValue.fromRawPointer(retValuePtr).value; } finally { WindowsDeleteString(hKey); diff --git a/lib/src/winrt/foundation/collections/ivector.dart b/lib/src/winrt/foundation/collections/ivector.dart index 8a48259a9f..492e7755e5 100644 --- a/lib/src/winrt/foundation/collections/ivector.dart +++ b/lib/src/winrt/foundation/collections/ivector.dart @@ -333,26 +333,25 @@ class IVector extends IInspectable implements IIterable { Uri _getAt_Uri(int index) { final retValuePtr = calloc(); - try { - final hr = - ptr.ref.vtable - .elementAt(6) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, Uint32, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, index, retValuePtr); + final hr = + ptr.ref.vtable + .elementAt(6) + .cast< + Pointer< + NativeFunction< + HRESULT Function( + Pointer, Uint32, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, index, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); + if (FAILED(hr)) throw WindowsException(hr); - final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); - return Uri.parse(winrtUri.toString()); - } finally { - free(retValuePtr); - } + final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); + final uriAsString = winrtUri.toString(); + winrtUri.release(); + + return Uri.parse(uriAsString); } /// Gets the number of items in the vector. @@ -382,29 +381,32 @@ class IVector extends IInspectable implements IIterable { List getView() { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(8) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); + final hr = ptr.ref.vtable + .elementAt(8) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - return IVectorView.fromRawPointer( - retValuePtr, - creator: _creator, - enumCreator: _enumCreator, - iterableIid: _iterableIid, - intType: _intType, - ).toList(); - } finally { + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final vectorView = IVectorView.fromRawPointer( + retValuePtr, + creator: _creator, + enumCreator: _enumCreator, + iterableIid: _iterableIid, + intType: _intType, + ); + final list = vectorView.toList(); + vectorView.release(); + + return list; } /// Retrieves the index of a specified item in the vector. @@ -690,7 +692,7 @@ class IVector extends IInspectable implements IIterable { return retValuePtr.value; } finally { - free(winrtUri.ptr); + winrtUri.release(); free(retValuePtr); } } @@ -872,7 +874,7 @@ class IVector extends IInspectable implements IIterable { if (FAILED(hr)) throw WindowsException(hr); } finally { - free(winrtUri.ptr); + winrtUri.release(); } } @@ -1060,7 +1062,7 @@ class IVector extends IInspectable implements IIterable { if (FAILED(hr)) throw WindowsException(hr); } finally { - free(winrtUri.ptr); + winrtUri.release(); } } @@ -1224,7 +1226,7 @@ class IVector extends IInspectable implements IIterable { if (FAILED(hr)) throw WindowsException(hr); } finally { - free(winrtUri.ptr); + winrtUri.release(); } } @@ -1783,12 +1785,12 @@ class IVector extends IInspectable implements IIterable { } void _replaceAll_Uri(List value) { - final handles = >[]; + final winrtUris = []; final pArray = calloc(value.length); for (var i = 0; i < value.length; i++) { final winrtUri = winrt_uri.Uri.createUri(value[i].toString()); pArray[i] = winrtUri.ptr.ref; - handles.add(winrtUri.ptr); + winrtUris.add(winrtUri); } try { @@ -1806,8 +1808,10 @@ class IVector extends IInspectable implements IIterable { if (FAILED(hr)) throw WindowsException(hr); } finally { + for (final winrtUri in winrtUris) { + winrtUri.release(); + } free(pArray); - handles.forEach(free); } } diff --git a/lib/src/winrt/foundation/collections/ivectorview.dart b/lib/src/winrt/foundation/collections/ivectorview.dart index ac3dfbd4b7..c36f4bb8d1 100644 --- a/lib/src/winrt/foundation/collections/ivectorview.dart +++ b/lib/src/winrt/foundation/collections/ivectorview.dart @@ -306,26 +306,25 @@ class IVectorView extends IInspectable implements IIterable { Uri _getAt_Uri(int index) { final retValuePtr = calloc(); - try { - final hr = - ptr.ref.vtable - .elementAt(6) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, Uint32, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, index, retValuePtr); + final hr = + ptr.ref.vtable + .elementAt(6) + .cast< + Pointer< + NativeFunction< + HRESULT Function( + Pointer, Uint32, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, index, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); + if (FAILED(hr)) throw WindowsException(hr); - final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); - return Uri.parse(winrtUri.toString()); - } finally { - free(retValuePtr); - } + final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); + final uriAsString = winrtUri.toString(); + winrtUri.release(); + + return Uri.parse(uriAsString); } String _getAt_String(int index) { @@ -634,7 +633,7 @@ class IVectorView extends IInspectable implements IIterable { return retValuePtr.value; } finally { - free(winrtUri.ptr); + winrtUri.release(); free(retValuePtr); } } From 9b46040b0faef62a240200dfa56c34ade940b3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:53:04 +0300 Subject: [PATCH 10/17] Fix toList extension method --- lib/src/winrt/internal/comobject_pointer.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/src/winrt/internal/comobject_pointer.dart b/lib/src/winrt/internal/comobject_pointer.dart index b74e251278..87c18cb8e3 100644 --- a/lib/src/winrt/internal/comobject_pointer.dart +++ b/lib/src/winrt/internal/comobject_pointer.dart @@ -6,6 +6,8 @@ import 'dart:ffi'; +import 'package:ffi/ffi.dart'; + import '../../combase.dart'; extension COMObjectPointer on Pointer { @@ -21,19 +23,20 @@ extension COMObjectPointer on Pointer { /// /// ```dart /// final pComObject = ... - /// final list = pComObject.toList(IHostName.fromRawPointer, - /// length: 4); + /// final list = pComObject.toList(StorageFile.fromRawPointer, length: 4); /// ``` /// /// {@category winrt} List toList(T Function(Pointer) creator, {int length = 1}) { final list = []; + for (var i = 0; i < length; i++) { - final element = this.elementAt(i); - if (element.ref.lpVtbl == nullptr) { - break; - } - list.add(creator(element)); + final objectPtr = this.elementAt(i); + if (objectPtr.ref.lpVtbl == nullptr) break; + // Move each element to a newly allocated pointer so that it can be + // freed properly. + final newObjectPtr = calloc()..ref = objectPtr.ref; + list.add(creator(newObjectPtr)); } return list; From 51e5aa0171cbcb46e2dc3711baf8d35690ccef36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:53:13 +0300 Subject: [PATCH 11/17] Free pArray --- lib/src/winrt/internal/vector_helper.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/winrt/internal/vector_helper.dart b/lib/src/winrt/internal/vector_helper.dart index ee5b448141..0d8034fd7c 100644 --- a/lib/src/winrt/internal/vector_helper.dart +++ b/lib/src/winrt/internal/vector_helper.dart @@ -72,8 +72,13 @@ class VectorHelper { List _toList_COMObject() { final pArray = calloc(length); - getManyCallback(0, length, pArray); - return pArray.toList(creator!, length: length); + + try { + getManyCallback(0, length, pArray); + return pArray.toList(creator!, length: length); + } finally { + free(pArray); + } } List _toList_enum() { From be5b3099c7a34f641993d2fbd7c7d56cd89633e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:53:24 +0300 Subject: [PATCH 12/17] Update IPropertyValue helpers --- .../internal/ipropertyvalue_helpers.dart | 103 +++++++++--------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/lib/src/winrt/internal/ipropertyvalue_helpers.dart b/lib/src/winrt/internal/ipropertyvalue_helpers.dart index 00a388b37a..e22df0bb6c 100644 --- a/lib/src/winrt/internal/ipropertyvalue_helpers.dart +++ b/lib/src/winrt/internal/ipropertyvalue_helpers.dart @@ -16,6 +16,7 @@ import '../../winrt_constants.dart'; import '../../winrt_helpers.dart'; import '../foundation/enums.g.dart'; import '../foundation/ipropertyvalue.dart'; +import '../foundation/ireference.dart'; import '../foundation/propertyvalue.dart'; import '../foundation/structs.g.dart'; import 'comobject_pointer.dart'; @@ -28,8 +29,8 @@ extension IPropertyValueHelper on IPropertyValue { if (ptr.ref.lpVtbl == nullptr) return null; // If the object does not implement the IPropertyValue interface, return it - // as an `IInspectable` object. - if (!iids.contains(IID_IPropertyValue)) return IInspectable(ptr); + // as an IInspectable object. + if (!iids.contains(IID_IPropertyValue)) return IInspectable.from(this); switch (this.type) { case PropertyType.boolean: @@ -200,6 +201,7 @@ List _inspectableListFromArray( getArrayCallback(pValueSize, pValue); return pValue.value.toList(IInspectable.new, length: pValueSize.value); } finally { + free(pValue); free(pValueSize); } } @@ -385,38 +387,38 @@ List _uint8ListFromArray( } } -Pointer _boxValue(Object value, {Type? nativeType}) { +IInspectable _boxValue(Object value, {Type? nativeType}) { // There is no need to box IInspectable objects since .createInspectable() // returns the object provided without modification. // See https://docs.microsoft.com/en-us/uwp/api/windows.foundation.PropertyValue.createinspectable - if (value is IInspectable) return value.ptr; + if (value is IInspectable) return value; - if (value is bool) return PropertyValue.createBoolean(value).ptr; - if (value is DateTime) return PropertyValue.createDateTime(value).ptr; + if (value is bool) return PropertyValue.createBoolean(value); + if (value is DateTime) return PropertyValue.createDateTime(value); if (value is double) { - if (nativeType == Float) return PropertyValue.createSingle(value).ptr; - return PropertyValue.createDouble(value).ptr; + if (nativeType == Float) return PropertyValue.createSingle(value); + return PropertyValue.createDouble(value); } - if (value is Duration) return PropertyValue.createTimeSpan(value).ptr; - if (value is Guid) return PropertyValue.createGuid(value).ptr; + if (value is Duration) return PropertyValue.createTimeSpan(value); + if (value is Guid) return PropertyValue.createGuid(value); if (value is int) { - if (nativeType == Int16) return PropertyValue.createInt16(value).ptr; - if (nativeType == Int32) return PropertyValue.createInt32(value).ptr; - if (nativeType == Uint8) return PropertyValue.createUInt8(value).ptr; - if (nativeType == Uint16) return PropertyValue.createUInt16(value).ptr; - if (nativeType == Uint32) return PropertyValue.createUInt32(value).ptr; - if (nativeType == Uint64) return PropertyValue.createUInt64(value).ptr; + if (nativeType == Int16) return PropertyValue.createInt16(value); + if (nativeType == Int32) return PropertyValue.createInt32(value); + if (nativeType == Uint8) return PropertyValue.createUInt8(value); + if (nativeType == Uint16) return PropertyValue.createUInt16(value); + if (nativeType == Uint32) return PropertyValue.createUInt32(value); + if (nativeType == Uint64) return PropertyValue.createUInt64(value); - return PropertyValue.createInt64(value).ptr; + return PropertyValue.createInt64(value); } - if (value is Point) return PropertyValue.createPoint(value).ptr; - if (value is Rect) return PropertyValue.createRect(value).ptr; - if (value is Size) return PropertyValue.createSize(value).ptr; - if (value is String) return PropertyValue.createString(value).ptr; + if (value is Point) return PropertyValue.createPoint(value); + if (value is Rect) return PropertyValue.createRect(value); + if (value is Size) return PropertyValue.createSize(value); + if (value is String) return PropertyValue.createString(value); if (value is List) return _boxBoolList(value); if (value is List) return _boxDateTimeList(value); @@ -476,33 +478,36 @@ String _referenceIidFromValue(Object value, Type? nativeType) { /// passed to APIs that take `IReference` interface as a parameter (e.g. /// `ToastNotification.expirationTime` setter). Pointer boxValue( - Object? value, { + Object value, { bool convertToIReference = false, Type? nativeType, }) { - if (value == null) return PropertyValue.createEmpty(); - - final propertyValuePtr = _boxValue(value, nativeType: nativeType); - if (!convertToIReference) return propertyValuePtr; + final propertyValue = _boxValue(value, nativeType: nativeType); + if (!convertToIReference) return propertyValue.ptr; final iid = _referenceIidFromValue(value, nativeType); - return IInspectable(propertyValuePtr).toInterface(iid); + final reference = IReference.fromRawPointer( + propertyValue.toInterface(iid), + referenceIid: iid); + propertyValue.release(); + + return reference.ptr; } -Pointer _boxBoolList(List list) { +IPropertyValue _boxBoolList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createBooleanArray(list.length, pArray).ptr; + return PropertyValue.createBooleanArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxDateTimeList(List list) { +IPropertyValue _boxDateTimeList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { final dateTimeValue = list @@ -514,104 +519,104 @@ Pointer _boxDateTimeList(List list) { } try { - return PropertyValue.createDateTimeArray(list.length, pArray).ptr; + return PropertyValue.createDateTimeArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxDoubleList(List list) { +IPropertyValue _boxDoubleList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createDoubleArray(list.length, pArray).ptr; + return PropertyValue.createDoubleArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxDurationList(List list) { +IPropertyValue _boxDurationList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i).inMicroseconds * 10; } try { - return PropertyValue.createTimeSpanArray(list.length, pArray).ptr; + return PropertyValue.createTimeSpanArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxGuidList(List list) { +IPropertyValue _boxGuidList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray.elementAt(i).ref.setGUID(list.elementAt(i).toString()); } try { - return PropertyValue.createGuidArray(list.length, pArray).ptr; + return PropertyValue.createGuidArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxPointList(List list) { +IPropertyValue _boxPointList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createPointArray(list.length, pArray).ptr; + return PropertyValue.createPointArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxRectList(List list) { +IPropertyValue _boxRectList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createRectArray(list.length, pArray).ptr; + return PropertyValue.createRectArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxSizeList(List list) { +IPropertyValue _boxSizeList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createSizeArray(list.length, pArray).ptr; + return PropertyValue.createSizeArray(list.length, pArray); } finally { free(pArray); } } -Pointer _boxIntList(List list) { +IPropertyValue _boxIntList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i); } try { - return PropertyValue.createInt64Array(list.length, pArray).ptr; + return PropertyValue.createInt64Array(list.length, pArray); } finally { free(pArray); } } -Pointer _boxStringList(List list) { +IPropertyValue _boxStringList(List list) { final handles = []; final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { @@ -620,21 +625,21 @@ Pointer _boxStringList(List list) { } try { - return PropertyValue.createStringArray(list.length, pArray).ptr; + return PropertyValue.createStringArray(list.length, pArray); } finally { free(pArray); handles.forEach(WindowsDeleteString); } } -Pointer _boxInspectableList(List list) { +IPropertyValue _boxInspectableList(List list) { final pArray = calloc(list.length); for (var i = 0; i < list.length; i++) { pArray[i] = list.elementAt(i).ptr.ref; } try { - return PropertyValue.createInspectableArray(list.length, pArray).ptr; + return PropertyValue.createInspectableArray(list.length, pArray); } finally { free(pArray); } From 8f0ce02007949e02331f6a9b3fb31b7b6f97c970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:55:17 +0300 Subject: [PATCH 13/17] Update projection classes --- .../winrt/declarations/comobject.dart | 3 ++ .../projection/winrt/declarations/map.dart | 34 +++++++------- .../winrt/declarations/reference.dart | 45 +++++++++++-------- .../projection/winrt/declarations/uri.dart | 31 +++++++------ .../projection/winrt/declarations/vector.dart | 36 ++++++++------- .../projection/winrt/declarations/void.dart | 2 + .../lib/src/projection/winrt/winrt_class.dart | 4 +- .../winrt/winrt_factory_interface_mapper.dart | 11 ++--- .../src/projection/winrt/winrt_parameter.dart | 12 ++--- .../winrt/winrt_static_interface_mapper.dart | 12 ++--- 10 files changed, 107 insertions(+), 83 deletions(-) diff --git a/tool/generator/lib/src/projection/winrt/declarations/comobject.dart b/tool/generator/lib/src/projection/winrt/declarations/comobject.dart index 46c873f46b..8659919394 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/comobject.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/comobject.dart @@ -38,8 +38,11 @@ class WinRTMethodReturningComObjectProjection extends WinRTMethodProjection $retType $camelCasedName($methodParams) { final retValuePtr = calloc(); $parametersPreamble + ${ffiCall(freeRetValOnFailure: true)} + $parametersPostamble + $returnStatement } '''; diff --git a/tool/generator/lib/src/projection/winrt/declarations/map.dart b/tool/generator/lib/src/projection/winrt/declarations/map.dart index 75fe27d638..34a269cdde 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/map.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/map.dart @@ -49,8 +49,11 @@ class WinRTMethodReturningMapProjection extends WinRTMethodProjection IMap<$mapTypeArgs> $camelCasedName($methodParams) { final retValuePtr = calloc(); $parametersPreamble + ${ffiCall(freeRetValOnFailure: true)} + $parametersPostamble + return IMap.fromRawPointer(retValuePtr$mapConstructorArgs); } '''; @@ -82,14 +85,14 @@ class WinRTMethodReturningMapViewProjection extends WinRTMethodProjection final retValuePtr = calloc(); $parametersPreamble - try { - ${ffiCall()} - return IMapView<$mapTypeArgs>.fromRawPointer - (retValuePtr$mapConstructorArgs).toMap(); - } finally { - $parametersPostamble - free(retValuePtr); - } + final mapView = IMapView<$mapTypeArgs>.fromRawPointer + (retValuePtr$mapConstructorArgs); + final map = mapView.toMap(); + mapView.release(); + + $parametersPostamble + + return map; } '''; } @@ -103,13 +106,14 @@ class WinRTGetPropertyReturningMapViewProjection Map<$mapTypeArgs> get $exposedMethodName { final retValuePtr = calloc(); - try { - ${ffiCall()} - return IMapView<$mapTypeArgs>.fromRawPointer - (retValuePtr$mapConstructorArgs).toMap(); - } finally { - free(retValuePtr); - } + ${ffiCall(freeRetValOnFailure: true)} + + final mapView = IMapView<$mapTypeArgs>.fromRawPointer + (retValuePtr$mapConstructorArgs); + final map = mapView.toMap(); + mapView.release(); + + return map; } '''; } diff --git a/tool/generator/lib/src/projection/winrt/declarations/reference.dart b/tool/generator/lib/src/projection/winrt/declarations/reference.dart index 07c6167292..7102007584 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/reference.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/reference.dart @@ -79,16 +79,20 @@ class WinRTMethodReturningReferenceProjection extends WinRTMethodProjection String toString() => ''' $referenceTypeArg? $camelCasedName($methodParams) { final retValuePtr = calloc(); + $parametersPreamble - try { - $parametersPreamble - ${ffiCall()} - return IReference<$referenceTypeArg>.fromRawPointer - (retValuePtr$referenceConstructorArgs).value; - } finally { - $parametersPostamble - free(retValuePtr); - } + ${ffiCall(freeRetValOnFailure: true)} + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference<$referenceTypeArg>.fromRawPointer + (retValuePtr$referenceConstructorArgs); + final value = reference.value; + reference.release(); + + $parametersPostamble + + return value; } '''; } @@ -103,13 +107,16 @@ class WinRTGetPropertyReturningReferenceProjection $referenceTypeArg? get $exposedMethodName { final retValuePtr = calloc(); - try { - ${ffiCall()} - return IReference<$referenceTypeArg>.fromRawPointer - (retValuePtr$referenceConstructorArgs).value; - } finally { - free(retValuePtr); - } + ${ffiCall(freeRetValOnFailure: true)} + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference<$referenceTypeArg>.fromRawPointer + (retValuePtr$referenceConstructorArgs); + final value = reference.value; + reference.release(); + + return value; } '''; } @@ -122,11 +129,13 @@ class WinRTSetPropertyReturningReferenceProjection @override String toString() => ''' set $exposedMethodName($referenceTypeArgFromParameter? value) { - final referencePtr = $boxValueMethodCall + final referencePtr = value == null + ? calloc() + : $boxValueMethodCall ${ffiCall(params: 'referencePtr.ref')} - free(referencePtr); + if (value == null) free(referencePtr); } '''; } diff --git a/tool/generator/lib/src/projection/winrt/declarations/uri.dart b/tool/generator/lib/src/projection/winrt/declarations/uri.dart index 7f8460f156..fd27589143 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/uri.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/uri.dart @@ -11,15 +11,15 @@ class WinRTMethodReturningUriProjection extends WinRTMethodProjection { final retValuePtr = calloc(); $parametersPreamble - try { - ${ffiCall()} + ${ffiCall(freeRetValOnFailure: true)} - final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); - return Uri.parse(winrtUri.toString()); - } finally { - $parametersPostamble - free(retValuePtr); - } + final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); + final uriAsString = winrtUri.toString(); + winrtUri.release(); + + $parametersPostamble + + return Uri.parse(uriAsString); } '''; } @@ -33,14 +33,13 @@ class WinRTGetPropertyReturningUriProjection Uri get $exposedMethodName { final retValuePtr = calloc(); - try { - ${ffiCall()} + ${ffiCall(freeRetValOnFailure: true)} - final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); - return Uri.parse(winrtUri.toString()); - } finally { - free(retValuePtr); - } + final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr); + final uriAsString = winrtUri.toString(); + winrtUri.release(); + + return Uri.parse(uriAsString); } '''; } @@ -57,7 +56,7 @@ class WinRTSetPropertyReturningUriProjection try { ${ffiCall(params: 'winrtUri.ptr.cast>().value')} } finally { - free(winrtUri.ptr); + winrtUri.release(); } } '''; diff --git a/tool/generator/lib/src/projection/winrt/declarations/vector.dart b/tool/generator/lib/src/projection/winrt/declarations/vector.dart index 415c00b52e..5f8c0200c6 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/vector.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/vector.dart @@ -58,8 +58,11 @@ class WinRTMethodReturningVectorProjection extends WinRTMethodProjection IVector<$vectorTypeArg> $camelCasedName($methodParams) { final retValuePtr = calloc(); $parametersPreamble + ${ffiCall(freeRetValOnFailure: true)} + $parametersPostamble + return IVector.fromRawPointer(retValuePtr$vectorConstructorArgs); } '''; @@ -91,14 +94,16 @@ class WinRTMethodReturningVectorViewProjection extends WinRTMethodProjection final retValuePtr = calloc(); $parametersPreamble - try { - ${ffiCall()} - return IVectorView<$vectorTypeArg>.fromRawPointer - (retValuePtr$vectorConstructorArgs).toList(); - } finally { - $parametersPostamble - free(retValuePtr); - } + ${ffiCall(freeRetValOnFailure: true)} + + final vectorView = IVectorView<$vectorTypeArg>.fromRawPointer + (retValuePtr$vectorConstructorArgs); + final list = vectorView.toList(); + vectorView.release(); + + $parametersPostamble + + return list; } '''; } @@ -113,13 +118,14 @@ class WinRTGetPropertyReturningVectorViewProjection List<$vectorTypeArg> get $exposedMethodName { final retValuePtr = calloc(); - try { - ${ffiCall()} - return IVectorView<$vectorTypeArg>.fromRawPointer - (retValuePtr$vectorConstructorArgs).toList(); - } finally { - free(retValuePtr); - } + ${ffiCall(freeRetValOnFailure: true)} + + final vectorView = IVectorView<$vectorTypeArg>.fromRawPointer + (retValuePtr$vectorConstructorArgs); + final list = vectorView.toList(); + vectorView.release(); + + return list; } '''; } diff --git a/tool/generator/lib/src/projection/winrt/declarations/void.dart b/tool/generator/lib/src/projection/winrt/declarations/void.dart index 7a7a38a6f4..43584b41ef 100644 --- a/tool/generator/lib/src/projection/winrt/declarations/void.dart +++ b/tool/generator/lib/src/projection/winrt/declarations/void.dart @@ -7,7 +7,9 @@ class WinRTMethodReturningVoidProjection extends WinRTMethodProjection { String toString() => ''' void $camelCasedName($methodParams) { $parametersPreamble + ${ffiCall()} + $parametersPostamble } '''; diff --git a/tool/generator/lib/src/projection/winrt/winrt_class.dart b/tool/generator/lib/src/projection/winrt/winrt_class.dart index c9cf4aa233..bd2eb170ee 100644 --- a/tool/generator/lib/src/projection/winrt/winrt_class.dart +++ b/tool/generator/lib/src/projection/winrt/winrt_class.dart @@ -23,9 +23,7 @@ class WinRTClassProjection extends WinRTInterfaceProjection { .isNotEmpty; String get defaultConstructor => hasDefaultConstructor - ? ''' - $shortName({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator));''' + ? '$shortName() : super(ActivateClass(_className));' : ''; String get classNameDeclaration => (hasDefaultConstructor || diff --git a/tool/generator/lib/src/projection/winrt/winrt_factory_interface_mapper.dart b/tool/generator/lib/src/projection/winrt/winrt_factory_interface_mapper.dart index 730280a2b0..5317a24fd0 100644 --- a/tool/generator/lib/src/projection/winrt/winrt_factory_interface_mapper.dart +++ b/tool/generator/lib/src/projection/winrt/winrt_factory_interface_mapper.dart @@ -30,14 +30,15 @@ class WinRTFactoryInterfaceMapperProjection extends WinRTClassProjection { for (final method in interfaceProjection.methodProjections) { methods.add(''' static $shortName ${method.camelCasedName}(${method.methodParams}) { - final activationFactory = - CreateActivationFactory(_className, IID_$shortFactoryInterfaceName); + final activationFactoryPtr = CreateActivationFactory( + _className, IID_$shortFactoryInterfaceName); + final object = + $shortFactoryInterfaceName.fromRawPointer(activationFactoryPtr); try { - return $shortFactoryInterfaceName.fromRawPointer - (activationFactory).${method.shortForm}; + return object.${method.shortForm}; } finally { - free(activationFactory); + object.release(); } }'''); } diff --git a/tool/generator/lib/src/projection/winrt/winrt_parameter.dart b/tool/generator/lib/src/projection/winrt/winrt_parameter.dart index 30af6fcb1b..955aef0ce6 100644 --- a/tool/generator/lib/src/projection/winrt/winrt_parameter.dart +++ b/tool/generator/lib/src/projection/winrt/winrt_parameter.dart @@ -82,9 +82,11 @@ class WinRTParameterProjection extends ParameterProjection { args.add('nativeType: ${typeProjection.nativeType}'); } - return typeProjection.isWinRTEnum - ? 'final ${name}ReferencePtr = boxValue(value.value, ${args.join(', ')});' - : 'final ${name}ReferencePtr = boxValue(value, ${args.join(', ')});'; + final valueArg = typeProjection.isWinRTEnum ? 'value.value' : 'value'; + return ''' + final ${name}ReferencePtr = value == null + ? calloc() + : boxValue($valueArg, ${args.join(', ')});'''; } if (isString) return 'final ${name}Hstring = convertToHString($name);'; @@ -101,10 +103,10 @@ class WinRTParameterProjection extends ParameterProjection { /// memory. String get postamble { if (isGuid) return 'free(${name}NativeGuidPtr);'; - if (isReference) return 'free(${name}ReferencePtr);'; + if (isReference) return 'if (value == null) free(${name}ReferencePtr);'; if (isString) return 'WindowsDeleteString(${name}Hstring);'; if (isUri && !methodBelongsToUriRuntimeClass) { - return 'free(${name}Uri.ptr);'; + return '${name}Uri.release();'; } return ''; diff --git a/tool/generator/lib/src/projection/winrt/winrt_static_interface_mapper.dart b/tool/generator/lib/src/projection/winrt/winrt_static_interface_mapper.dart index 9aa69290b1..b87e908078 100644 --- a/tool/generator/lib/src/projection/winrt/winrt_static_interface_mapper.dart +++ b/tool/generator/lib/src/projection/winrt/winrt_static_interface_mapper.dart @@ -28,21 +28,21 @@ class WinRTStaticInterfaceMapperProjection extends WinRTClassProjection { final interfaceProjection = WinRTInterfaceProjection(staticTypeDef); for (final methodProjection in interfaceProjection.methodProjections) { - final statement = ''' - $shortStaticInterfaceName.fromRawPointer - (activationFactory).${methodProjection.shortForm};'''; + final statement = 'object.${methodProjection.shortForm};'; final returnStatement = methodProjection.method.isSetProperty ? statement : 'return $statement'; methods.add(''' static ${methodProjection.shortDeclaration} { - final activationFactory = - CreateActivationFactory(_className, IID_$shortStaticInterfaceName); + final activationFactoryPtr = CreateActivationFactory( + _className, IID_$shortStaticInterfaceName); + final object = + $shortStaticInterfaceName.fromRawPointer(activationFactoryPtr); try { $returnStatement } finally { - free(activationFactory); + object.release(); } }'''); } From 6806678ba49c9171918fa1f17574c073dc5413f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:56:06 +0300 Subject: [PATCH 14/17] Regenerate files --- .../winrt/data/json/ijsonarraystatics.dart | 3 + lib/src/winrt/data/json/ijsonobject.dart | 10 + .../winrt/data/json/ijsonobjectstatics.dart | 3 + .../json/ijsonobjectwithdefaultvalues.dart | 3 + .../winrt/data/json/ijsonvaluestatics.dart | 6 + lib/src/winrt/data/json/jsonarray.dart | 18 +- lib/src/winrt/data/json/jsonobject.dart | 18 +- lib/src/winrt/data/json/jsonvalue.dart | 47 +-- .../devices/enumeration/devicepicker.dart | 3 +- .../winrt/devices/power/ibatteryreport.dart | 148 ++++---- .../winrt/foundation/collections/imap.dart | 32 +- .../foundation/collections/propertyset.dart | 3 +- .../foundation/collections/stringmap.dart | 3 +- .../foundation/collections/valueset.dart | 3 +- .../foundation/ipropertyvaluestatics.dart | 8 + .../winrt/foundation/iuriruntimeclass.dart | 3 + .../foundation/iuriruntimeclassfactory.dart | 6 + ...iwwwformurldecoderruntimeclassfactory.dart | 3 + lib/src/winrt/foundation/propertyvalue.dart | 312 ++++++++-------- lib/src/winrt/foundation/uri.dart | 32 +- .../winrt/foundation/wwwformurldecoder.dart | 10 +- lib/src/winrt/gaming/input/gamepad.dart | 47 +-- .../winrt/gaming/input/igamepadstatics.dart | 37 +- lib/src/winrt/globalization/calendar.dart | 28 +- lib/src/winrt/globalization/icalendar.dart | 38 +- .../winrt/globalization/icalendarfactory.dart | 2 + .../globalization/icalendarfactory2.dart | 2 + .../globalization/itimezoneoncalendar.dart | 2 + .../iphonenumberformatterstatics.dart | 1 + .../iphonenumberinfofactory.dart | 3 + .../phonenumberformatter.dart | 40 +- .../phonenumberinfo.dart | 24 +- .../printing3dmultiplepropertymaterial.dart | 3 +- .../mediaproperties/mediapropertyset.dart | 3 +- .../connectivity/iipinformation.dart | 37 +- .../inetworkinformationstatics.dart | 343 ++++++++---------- lib/src/winrt/networking/hostname.dart | 16 +- .../winrt/networking/ihostnamefactory.dart | 3 + lib/src/winrt/storage/istorageitem.dart | 4 + .../winrt/storage/pickers/fileopenpicker.dart | 11 +- lib/src/winrt/storage/userdatapaths.dart | 16 +- .../ui/notifications/itoastnotification.dart | 41 ++- .../ui/notifications/notificationdata.dart | 23 +- .../ui/notifications/toastnotification.dart | 17 +- .../winrt/ui/viewmanagement/uisettings.dart | 3 +- 45 files changed, 750 insertions(+), 668 deletions(-) diff --git a/lib/src/winrt/data/json/ijsonarraystatics.dart b/lib/src/winrt/data/json/ijsonarraystatics.dart index be0f439826..73de0e3445 100644 --- a/lib/src/winrt/data/json/ijsonarraystatics.dart +++ b/lib/src/winrt/data/json/ijsonarraystatics.dart @@ -38,6 +38,7 @@ class IJsonArrayStatics extends IInspectable { JsonArray parse(String input) { final retValuePtr = calloc(); final inputHstring = convertToHString(input); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -53,7 +54,9 @@ class IJsonArrayStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(inputHstring); + return JsonArray.fromRawPointer(retValuePtr); } diff --git a/lib/src/winrt/data/json/ijsonobject.dart b/lib/src/winrt/data/json/ijsonobject.dart index bff7393c30..daf1110e5c 100644 --- a/lib/src/winrt/data/json/ijsonobject.dart +++ b/lib/src/winrt/data/json/ijsonobject.dart @@ -41,6 +41,7 @@ class IJsonObject extends IInspectable implements IJsonValue { JsonValue getNamedValue(String name) { final retValuePtr = calloc(); final nameHstring = convertToHString(name); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -56,7 +57,9 @@ class IJsonObject extends IInspectable implements IJsonValue { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); + return JsonValue.fromRawPointer(retValuePtr); } @@ -78,12 +81,14 @@ class IJsonObject extends IInspectable implements IJsonValue { value.ptr.cast>().value); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(nameHstring); } JsonObject getNamedObject(String name) { final retValuePtr = calloc(); final nameHstring = convertToHString(name); + final hr = ptr.ref.vtable .elementAt(8) .cast< @@ -99,13 +104,16 @@ class IJsonObject extends IInspectable implements IJsonValue { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); + return JsonObject.fromRawPointer(retValuePtr); } JsonArray getNamedArray(String name) { final retValuePtr = calloc(); final nameHstring = convertToHString(name); + final hr = ptr.ref.vtable .elementAt(9) .cast< @@ -121,7 +129,9 @@ class IJsonObject extends IInspectable implements IJsonValue { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); + return JsonArray.fromRawPointer(retValuePtr); } diff --git a/lib/src/winrt/data/json/ijsonobjectstatics.dart b/lib/src/winrt/data/json/ijsonobjectstatics.dart index 8e5533f6aa..066aa285ec 100644 --- a/lib/src/winrt/data/json/ijsonobjectstatics.dart +++ b/lib/src/winrt/data/json/ijsonobjectstatics.dart @@ -38,6 +38,7 @@ class IJsonObjectStatics extends IInspectable { JsonObject parse(String input) { final retValuePtr = calloc(); final inputHstring = convertToHString(input); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -53,7 +54,9 @@ class IJsonObjectStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(inputHstring); + return JsonObject.fromRawPointer(retValuePtr); } diff --git a/lib/src/winrt/data/json/ijsonobjectwithdefaultvalues.dart b/lib/src/winrt/data/json/ijsonobjectwithdefaultvalues.dart index 14b6f9127c..275f17be1f 100644 --- a/lib/src/winrt/data/json/ijsonobjectwithdefaultvalues.dart +++ b/lib/src/winrt/data/json/ijsonobjectwithdefaultvalues.dart @@ -66,6 +66,7 @@ class IJsonObjectWithDefaultValues extends IInspectable free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); return JsonValue.fromRawPointer(retValuePtr); @@ -95,6 +96,7 @@ class IJsonObjectWithDefaultValues extends IInspectable free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); return JsonObject.fromRawPointer(retValuePtr); @@ -155,6 +157,7 @@ class IJsonObjectWithDefaultValues extends IInspectable free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(nameHstring); return JsonArray.fromRawPointer(retValuePtr); diff --git a/lib/src/winrt/data/json/ijsonvaluestatics.dart b/lib/src/winrt/data/json/ijsonvaluestatics.dart index 0de001983e..dbe889ff1d 100644 --- a/lib/src/winrt/data/json/ijsonvaluestatics.dart +++ b/lib/src/winrt/data/json/ijsonvaluestatics.dart @@ -38,6 +38,7 @@ class IJsonValueStatics extends IInspectable { JsonValue parse(String input) { final retValuePtr = calloc(); final inputHstring = convertToHString(input); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -53,7 +54,9 @@ class IJsonValueStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(inputHstring); + return JsonValue.fromRawPointer(retValuePtr); } @@ -135,6 +138,7 @@ class IJsonValueStatics extends IInspectable { JsonValue createStringValue(String input) { final retValuePtr = calloc(); final inputHstring = convertToHString(input); + final hr = ptr.ref.vtable .elementAt(10) .cast< @@ -150,7 +154,9 @@ class IJsonValueStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(inputHstring); + return JsonValue.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/data/json/jsonarray.dart b/lib/src/winrt/data/json/jsonarray.dart index 059d20c608..c9712ed85c 100644 --- a/lib/src/winrt/data/json/jsonarray.dart +++ b/lib/src/winrt/data/json/jsonarray.dart @@ -42,33 +42,33 @@ class JsonArray extends IInspectable IVector, IIterable, IStringable { - JsonArray({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + JsonArray() : super(ActivateClass(_className)); JsonArray.fromRawPointer(super.ptr); static const _className = 'Windows.Data.Json.JsonArray'; // IJsonArrayStatics methods static JsonArray parse(String input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonArrayStatics); + final object = IJsonArrayStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonArrayStatics.fromRawPointer(activationFactory).parse(input); + return object.parse(input); } finally { - free(activationFactory); + object.release(); } } static bool tryParse(String input, JsonArray result) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonArrayStatics); + final object = IJsonArrayStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonArrayStatics.fromRawPointer(activationFactory) - .tryParse(input, result); + return object.tryParse(input, result); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/data/json/jsonobject.dart b/lib/src/winrt/data/json/jsonobject.dart index 0533e95b07..8808775ff1 100644 --- a/lib/src/winrt/data/json/jsonobject.dart +++ b/lib/src/winrt/data/json/jsonobject.dart @@ -47,33 +47,33 @@ class JsonObject extends IInspectable IIterable>, IJsonObjectWithDefaultValues, IStringable { - JsonObject({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + JsonObject() : super(ActivateClass(_className)); JsonObject.fromRawPointer(super.ptr); static const _className = 'Windows.Data.Json.JsonObject'; // IJsonObjectStatics methods static JsonObject parse(String input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonObjectStatics); + final object = IJsonObjectStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonObjectStatics.fromRawPointer(activationFactory).parse(input); + return object.parse(input); } finally { - free(activationFactory); + object.release(); } } static bool tryParse(String input, JsonObject result) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonObjectStatics); + final object = IJsonObjectStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonObjectStatics.fromRawPointer(activationFactory) - .tryParse(input, result); + return object.tryParse(input, result); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/data/json/jsonvalue.dart b/lib/src/winrt/data/json/jsonvalue.dart index aebbd307c9..2287457c73 100644 --- a/lib/src/winrt/data/json/jsonvalue.dart +++ b/lib/src/winrt/data/json/jsonvalue.dart @@ -39,74 +39,75 @@ class JsonValue extends IInspectable implements IJsonValue, IStringable { // IJsonValueStatics methods static JsonValue parse(String input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics); + final object = IJsonValueStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics.fromRawPointer(activationFactory).parse(input); + return object.parse(input); } finally { - free(activationFactory); + object.release(); } } static bool tryParse(String input, JsonValue result) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics); + final object = IJsonValueStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics.fromRawPointer(activationFactory) - .tryParse(input, result); + return object.tryParse(input, result); } finally { - free(activationFactory); + object.release(); } } static JsonValue createBooleanValue(bool input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics); + final object = IJsonValueStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics.fromRawPointer(activationFactory) - .createBooleanValue(input); + return object.createBooleanValue(input); } finally { - free(activationFactory); + object.release(); } } static JsonValue createNumberValue(double input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics); + final object = IJsonValueStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics.fromRawPointer(activationFactory) - .createNumberValue(input); + return object.createNumberValue(input); } finally { - free(activationFactory); + object.release(); } } static JsonValue createStringValue(String input) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics); + final object = IJsonValueStatics.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics.fromRawPointer(activationFactory) - .createStringValue(input); + return object.createStringValue(input); } finally { - free(activationFactory); + object.release(); } } // IJsonValueStatics2 methods static JsonValue createNullValue() { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IJsonValueStatics2); + final object = IJsonValueStatics2.fromRawPointer(activationFactoryPtr); try { - return IJsonValueStatics2.fromRawPointer(activationFactory) - .createNullValue(); + return object.createNullValue(); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/devices/enumeration/devicepicker.dart b/lib/src/winrt/devices/enumeration/devicepicker.dart index d407d6e64a..344cbbf83d 100644 --- a/lib/src/winrt/devices/enumeration/devicepicker.dart +++ b/lib/src/winrt/devices/enumeration/devicepicker.dart @@ -31,8 +31,7 @@ import '../../../winrt_helpers.dart'; /// {@category Class} /// {@category winrt} class DevicePicker extends IInspectable implements IDevicePicker { - DevicePicker({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + DevicePicker() : super(ActivateClass(_className)); DevicePicker.fromRawPointer(super.ptr); static const _className = 'Windows.Devices.Enumeration.DevicePicker'; diff --git a/lib/src/winrt/devices/power/ibatteryreport.dart b/lib/src/winrt/devices/power/ibatteryreport.dart index fedd4c1990..b9c30fc29e 100644 --- a/lib/src/winrt/devices/power/ibatteryreport.dart +++ b/lib/src/winrt/devices/power/ibatteryreport.dart @@ -39,93 +39,113 @@ class IBatteryReport extends IInspectable { int? get chargeRateInMilliwatts { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(6) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}') - .value; - } finally { + final hr = ptr.ref.vtable + .elementAt(6) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}'); + final value = reference.value; + reference.release(); + + return value; } int? get designCapacityInMilliwattHours { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(7) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}') - .value; - } finally { + final hr = ptr.ref.vtable + .elementAt(7) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}'); + final value = reference.value; + reference.release(); + + return value; } int? get fullChargeCapacityInMilliwattHours { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(8) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}') - .value; - } finally { + final hr = ptr.ref.vtable + .elementAt(8) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}'); + final value = reference.value; + reference.release(); + + return value; } int? get remainingCapacityInMilliwattHours { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}') - .value; - } finally { + final hr = ptr.ref.vtable + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{548cefbd-bc8a-5fa0-8df2-957440fc8bf4}'); + final value = reference.value; + reference.release(); + + return value; } BatteryStatus get status { diff --git a/lib/src/winrt/foundation/collections/imap.dart b/lib/src/winrt/foundation/collections/imap.dart index 98025dcae8..c95c9e1dbf 100644 --- a/lib/src/winrt/foundation/collections/imap.dart +++ b/lib/src/winrt/foundation/collections/imap.dart @@ -541,10 +541,10 @@ class IMap extends IInspectable bool insert(K key, V value) { if (isSameType()) { if (isSubtypeOfInspectable()) { - return _insert_Guid_Object(key as Guid, (value as IInspectable).ptr); + return _insert_Guid_Object(key as Guid, value); } - return _insert_Guid_Object(key as Guid, boxValue(value)); + return _insert_Guid_Object(key as Guid, value); } if (isSameType()) { @@ -562,23 +562,24 @@ class IMap extends IInspectable } if (isSubtypeOfInspectable()) { - return _insert_String_Object( - key as String, (value as IInspectable).ptr); + return _insert_String_Object(key as String, value); } if (isSubtypeOfWinRTEnum()) { return _insert_String_enum(key as String, value as WinRTEnum); } - return _insert_String_Object(key as String, boxValue(value)); + return _insert_String_Object(key as String, value); } - return _insert_Object_Object(key as IInspectable, boxValue(value)); + return _insert_Object_Object(key as IInspectable, value); } - bool _insert_Guid_Object(Guid key, Pointer value) { + bool _insert_Guid_Object(Guid key, V value) { final retValuePtr = calloc(); final nativeGuidPtr = key.toNativeGUID(); + final propertyValuePtr = + value == null ? calloc() : boxValue(value); try { final hr = ptr.ref.lpVtbl.value @@ -591,12 +592,13 @@ class IMap extends IInspectable .value .asFunction< int Function(Pointer, GUID, COMObject, Pointer)>()( - ptr.ref.lpVtbl, nativeGuidPtr.ref, value.ref, retValuePtr); + ptr.ref.lpVtbl, nativeGuidPtr.ref, propertyValuePtr.ref, retValuePtr); if (FAILED(hr)) throw WindowsException(hr); return retValuePtr.value; } finally { + if (value == null) free(propertyValuePtr); free(nativeGuidPtr); free(retValuePtr); } @@ -626,8 +628,10 @@ class IMap extends IInspectable } } - bool _insert_Object_Object(IInspectable key, Pointer value) { + bool _insert_Object_Object(IInspectable key, V value) { final retValuePtr = calloc(); + final propertyValuePtr = + value == null ? calloc() : boxValue(value); try { final hr = ptr.ref.lpVtbl.value @@ -640,12 +644,13 @@ class IMap extends IInspectable .value .asFunction< int Function(Pointer, COMObject, COMObject, Pointer)>()( - ptr.ref.lpVtbl, key.ptr.ref, value.ref, retValuePtr); + ptr.ref.lpVtbl, key.ptr.ref, propertyValuePtr.ref, retValuePtr); if (FAILED(hr)) throw WindowsException(hr); return retValuePtr.value; } finally { + if (value == null) propertyValuePtr; free(retValuePtr); } } @@ -675,9 +680,11 @@ class IMap extends IInspectable } } - bool _insert_String_Object(String key, Pointer value) { + bool _insert_String_Object(String key, V value) { final retValuePtr = calloc(); final hKey = convertToHString(key); + final propertyValuePtr = + value == null ? calloc() : boxValue(value); try { final hr = ptr.ref.lpVtbl.value @@ -690,12 +697,13 @@ class IMap extends IInspectable .value .asFunction< int Function(Pointer, int, COMObject, Pointer)>()( - ptr.ref.lpVtbl, hKey, value.ref, retValuePtr); + ptr.ref.lpVtbl, hKey, propertyValuePtr.ref, retValuePtr); if (FAILED(hr)) throw WindowsException(hr); return retValuePtr.value; } finally { + if (value == null) free(propertyValuePtr); WindowsDeleteString(hKey); free(retValuePtr); } diff --git a/lib/src/winrt/foundation/collections/propertyset.dart b/lib/src/winrt/foundation/collections/propertyset.dart index d44ab62241..323e128710 100644 --- a/lib/src/winrt/foundation/collections/propertyset.dart +++ b/lib/src/winrt/foundation/collections/propertyset.dart @@ -39,8 +39,7 @@ class PropertySet extends IInspectable IObservableMap, IMap, IIterable> { - PropertySet({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + PropertySet() : super(ActivateClass(_className)); PropertySet.fromRawPointer(super.ptr); static const _className = 'Windows.Foundation.Collections.PropertySet'; diff --git a/lib/src/winrt/foundation/collections/stringmap.dart b/lib/src/winrt/foundation/collections/stringmap.dart index ee0dbc0bb0..44350028a5 100644 --- a/lib/src/winrt/foundation/collections/stringmap.dart +++ b/lib/src/winrt/foundation/collections/stringmap.dart @@ -36,8 +36,7 @@ class StringMap extends IInspectable IMap, IIterable>, IObservableMap { - StringMap({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + StringMap() : super(ActivateClass(_className)); StringMap.fromRawPointer(super.ptr); static const _className = 'Windows.Foundation.Collections.StringMap'; diff --git a/lib/src/winrt/foundation/collections/valueset.dart b/lib/src/winrt/foundation/collections/valueset.dart index 4bc36b3c29..35c9481185 100644 --- a/lib/src/winrt/foundation/collections/valueset.dart +++ b/lib/src/winrt/foundation/collections/valueset.dart @@ -42,8 +42,7 @@ class ValueSet extends IInspectable IObservableMap, IMap, IIterable> { - ValueSet({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + ValueSet() : super(ActivateClass(_className)); ValueSet.fromRawPointer(super.ptr); static const _className = 'Windows.Foundation.Collections.ValueSet'; diff --git a/lib/src/winrt/foundation/ipropertyvaluestatics.dart b/lib/src/winrt/foundation/ipropertyvaluestatics.dart index b997fbdd77..28cdf3d3f3 100644 --- a/lib/src/winrt/foundation/ipropertyvaluestatics.dart +++ b/lib/src/winrt/foundation/ipropertyvaluestatics.dart @@ -306,6 +306,7 @@ class IPropertyValueStatics extends IInspectable { IPropertyValue createString(String value) { final retValuePtr = calloc(); final valueHstring = convertToHString(value); + final hr = ptr.ref.vtable .elementAt(18) .cast< @@ -321,7 +322,9 @@ class IPropertyValueStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(valueHstring); + return IPropertyValue.fromRawPointer(retValuePtr); } @@ -352,6 +355,7 @@ class IPropertyValueStatics extends IInspectable { IPropertyValue createGuid(Guid value) { final retValuePtr = calloc(); final valueNativeGuidPtr = value.toNativeGUID(); + final hr = ptr.ref.vtable .elementAt(20) .cast< @@ -368,7 +372,9 @@ class IPropertyValueStatics extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + free(valueNativeGuidPtr); + return IPropertyValue.fromRawPointer(retValuePtr); } @@ -376,6 +382,7 @@ class IPropertyValueStatics extends IInspectable { final retValuePtr = calloc(); final valueDateTime = value.difference(DateTime.utc(1601, 01, 01)).inMicroseconds * 10; + final hr = ptr.ref.vtable .elementAt(21) .cast< @@ -398,6 +405,7 @@ class IPropertyValueStatics extends IInspectable { IPropertyValue createTimeSpan(Duration value) { final retValuePtr = calloc(); final valueDuration = value.inMicroseconds * 10; + final hr = ptr.ref.vtable .elementAt(22) .cast< diff --git a/lib/src/winrt/foundation/iuriruntimeclass.dart b/lib/src/winrt/foundation/iuriruntimeclass.dart index 8a61245938..20310abacb 100644 --- a/lib/src/winrt/foundation/iuriruntimeclass.dart +++ b/lib/src/winrt/foundation/iuriruntimeclass.dart @@ -422,6 +422,7 @@ class IUriRuntimeClass extends IInspectable { Uri combineUri(String relativeUri) { final retValuePtr = calloc(); final relativeUriHstring = convertToHString(relativeUri); + final hr = ptr.ref.vtable .elementAt(22) .cast< @@ -438,7 +439,9 @@ class IUriRuntimeClass extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(relativeUriHstring); + return Uri.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/foundation/iuriruntimeclassfactory.dart b/lib/src/winrt/foundation/iuriruntimeclassfactory.dart index bad0bbabd7..e9a76ea7e5 100644 --- a/lib/src/winrt/foundation/iuriruntimeclassfactory.dart +++ b/lib/src/winrt/foundation/iuriruntimeclassfactory.dart @@ -38,6 +38,7 @@ class IUriRuntimeClassFactory extends IInspectable { Uri createUri(String uri) { final retValuePtr = calloc(); final uriHstring = convertToHString(uri); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -53,7 +54,9 @@ class IUriRuntimeClassFactory extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(uriHstring); + return Uri.fromRawPointer(retValuePtr); } @@ -61,6 +64,7 @@ class IUriRuntimeClassFactory extends IInspectable { final retValuePtr = calloc(); final baseUriHstring = convertToHString(baseUri); final relativeUriHstring = convertToHString(relativeUri); + final hr = ptr.ref.vtable .elementAt(7) .cast< @@ -78,8 +82,10 @@ class IUriRuntimeClassFactory extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(baseUriHstring); WindowsDeleteString(relativeUriHstring); + return Uri.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/foundation/iwwwformurldecoderruntimeclassfactory.dart b/lib/src/winrt/foundation/iwwwformurldecoderruntimeclassfactory.dart index 0401eb5bf5..7297835118 100644 --- a/lib/src/winrt/foundation/iwwwformurldecoderruntimeclassfactory.dart +++ b/lib/src/winrt/foundation/iwwwformurldecoderruntimeclassfactory.dart @@ -39,6 +39,7 @@ class IWwwFormUrlDecoderRuntimeClassFactory extends IInspectable { WwwFormUrlDecoder createWwwFormUrlDecoder(String query) { final retValuePtr = calloc(); final queryHstring = convertToHString(query); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -54,7 +55,9 @@ class IWwwFormUrlDecoderRuntimeClassFactory extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(queryHstring); + return WwwFormUrlDecoder.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/foundation/propertyvalue.dart b/lib/src/winrt/foundation/propertyvalue.dart index f4ebb4ebab..2664f3d5f0 100644 --- a/lib/src/winrt/foundation/propertyvalue.dart +++ b/lib/src/winrt/foundation/propertyvalue.dart @@ -37,479 +37,479 @@ class PropertyValue extends IInspectable { // IPropertyValueStatics methods static Pointer createEmpty() { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createEmpty(); + return object.createEmpty(); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt8(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt8(value); + return object.createUInt8(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt16(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt16(value); + return object.createInt16(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt16(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt16(value); + return object.createUInt16(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt32(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt32(value); + return object.createInt32(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt32(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt32(value); + return object.createUInt32(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt64(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt64(value); + return object.createInt64(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt64(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt64(value); + return object.createUInt64(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createSingle(double value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createSingle(value); + return object.createSingle(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createDouble(double value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createDouble(value); + return object.createDouble(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createChar16(int value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createChar16(value); + return object.createChar16(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createBoolean(bool value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createBoolean(value); + return object.createBoolean(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createString(String value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createString(value); + return object.createString(value); } finally { - free(activationFactory); + object.release(); } } static Pointer createInspectable(Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInspectable(value); + return object.createInspectable(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createGuid(Guid value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createGuid(value); + return object.createGuid(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createDateTime(DateTime value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createDateTime(value); + return object.createDateTime(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createTimeSpan(Duration value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createTimeSpan(value); + return object.createTimeSpan(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createPoint(Point value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createPoint(value); + return object.createPoint(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createSize(Size value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createSize(value); + return object.createSize(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createRect(Rect value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createRect(value); + return object.createRect(value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt8Array(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt8Array(valueSize, value); + return object.createUInt8Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt16Array(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt16Array(valueSize, value); + return object.createInt16Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt16Array( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt16Array(valueSize, value); + return object.createUInt16Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt32Array(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt32Array(valueSize, value); + return object.createInt32Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt32Array( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt32Array(valueSize, value); + return object.createUInt32Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInt64Array(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInt64Array(valueSize, value); + return object.createInt64Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createUInt64Array( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createUInt64Array(valueSize, value); + return object.createUInt64Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createSingleArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createSingleArray(valueSize, value); + return object.createSingleArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createDoubleArray( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createDoubleArray(valueSize, value); + return object.createDoubleArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createChar16Array( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createChar16Array(valueSize, value); + return object.createChar16Array(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createBooleanArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createBooleanArray(valueSize, value); + return object.createBooleanArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createStringArray( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createStringArray(valueSize, value); + return object.createStringArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createInspectableArray( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createInspectableArray(valueSize, value); + return object.createInspectableArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createGuidArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createGuidArray(valueSize, value); + return object.createGuidArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createDateTimeArray( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createDateTimeArray(valueSize, value); + return object.createDateTimeArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createTimeSpanArray( int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createTimeSpanArray(valueSize, value); + return object.createTimeSpanArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createPointArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createPointArray(valueSize, value); + return object.createPointArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createSizeArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createSizeArray(valueSize, value); + return object.createSizeArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } static IPropertyValue createRectArray(int valueSize, Pointer value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPropertyValueStatics); + final object = IPropertyValueStatics.fromRawPointer(activationFactoryPtr); try { - return IPropertyValueStatics.fromRawPointer(activationFactory) - .createRectArray(valueSize, value); + return object.createRectArray(valueSize, value); } finally { - free(activationFactory); + object.release(); } } } diff --git a/lib/src/winrt/foundation/uri.dart b/lib/src/winrt/foundation/uri.dart index b0c6d8d038..0de33819a0 100644 --- a/lib/src/winrt/foundation/uri.dart +++ b/lib/src/winrt/foundation/uri.dart @@ -45,51 +45,51 @@ class Uri extends IInspectable // IUriRuntimeClassFactory methods static Uri createUri(String uri) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUriRuntimeClassFactory); + final object = IUriRuntimeClassFactory.fromRawPointer(activationFactoryPtr); try { - return IUriRuntimeClassFactory.fromRawPointer(activationFactory) - .createUri(uri); + return object.createUri(uri); } finally { - free(activationFactory); + object.release(); } } static Uri createWithRelativeUri(String baseUri, String relativeUri) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUriRuntimeClassFactory); + final object = IUriRuntimeClassFactory.fromRawPointer(activationFactoryPtr); try { - return IUriRuntimeClassFactory.fromRawPointer(activationFactory) - .createWithRelativeUri(baseUri, relativeUri); + return object.createWithRelativeUri(baseUri, relativeUri); } finally { - free(activationFactory); + object.release(); } } // IUriEscapeStatics methods static String unescapeComponent(String toUnescape) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUriEscapeStatics); + final object = IUriEscapeStatics.fromRawPointer(activationFactoryPtr); try { - return IUriEscapeStatics.fromRawPointer(activationFactory) - .unescapeComponent(toUnescape); + return object.unescapeComponent(toUnescape); } finally { - free(activationFactory); + object.release(); } } static String escapeComponent(String toEscape) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUriEscapeStatics); + final object = IUriEscapeStatics.fromRawPointer(activationFactoryPtr); try { - return IUriEscapeStatics.fromRawPointer(activationFactory) - .escapeComponent(toEscape); + return object.escapeComponent(toEscape); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/foundation/wwwformurldecoder.dart b/lib/src/winrt/foundation/wwwformurldecoder.dart index c4a0ee045d..d749cbc35f 100644 --- a/lib/src/winrt/foundation/wwwformurldecoder.dart +++ b/lib/src/winrt/foundation/wwwformurldecoder.dart @@ -43,15 +43,15 @@ class WwwFormUrlDecoder extends IInspectable // IWwwFormUrlDecoderRuntimeClassFactory methods static WwwFormUrlDecoder createWwwFormUrlDecoder(String query) { - final activationFactory = CreateActivationFactory( + final activationFactoryPtr = CreateActivationFactory( _className, IID_IWwwFormUrlDecoderRuntimeClassFactory); + final object = IWwwFormUrlDecoderRuntimeClassFactory.fromRawPointer( + activationFactoryPtr); try { - return IWwwFormUrlDecoderRuntimeClassFactory.fromRawPointer( - activationFactory) - .createWwwFormUrlDecoder(query); + return object.createWwwFormUrlDecoder(query); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/gaming/input/gamepad.dart b/lib/src/winrt/gaming/input/gamepad.dart index 573ffb050e..c4751ff966 100644 --- a/lib/src/winrt/gaming/input/gamepad.dart +++ b/lib/src/winrt/gaming/input/gamepad.dart @@ -49,74 +49,75 @@ class Gamepad extends IInspectable // IGamepadStatics methods static int add_GamepadAdded(Pointer> value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics); + final object = IGamepadStatics.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics.fromRawPointer(activationFactory) - .add_GamepadAdded(value); + return object.add_GamepadAdded(value); } finally { - free(activationFactory); + object.release(); } } static void remove_GamepadAdded(int token) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics); + final object = IGamepadStatics.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics.fromRawPointer(activationFactory) - .remove_GamepadAdded(token); + return object.remove_GamepadAdded(token); } finally { - free(activationFactory); + object.release(); } } static int add_GamepadRemoved(Pointer> value) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics); + final object = IGamepadStatics.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics.fromRawPointer(activationFactory) - .add_GamepadRemoved(value); + return object.add_GamepadRemoved(value); } finally { - free(activationFactory); + object.release(); } } static void remove_GamepadRemoved(int token) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics); + final object = IGamepadStatics.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics.fromRawPointer(activationFactory) - .remove_GamepadRemoved(token); + return object.remove_GamepadRemoved(token); } finally { - free(activationFactory); + object.release(); } } static List get gamepads { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics); + final object = IGamepadStatics.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics.fromRawPointer(activationFactory).gamepads; + return object.gamepads; } finally { - free(activationFactory); + object.release(); } } // IGamepadStatics2 methods static Gamepad fromGameController(IGameController gameController) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IGamepadStatics2); + final object = IGamepadStatics2.fromRawPointer(activationFactoryPtr); try { - return IGamepadStatics2.fromRawPointer(activationFactory) - .fromGameController(gameController); + return object.fromGameController(gameController); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/gaming/input/igamepadstatics.dart b/lib/src/winrt/gaming/input/igamepadstatics.dart index b0af944b90..073932115e 100644 --- a/lib/src/winrt/gaming/input/igamepadstatics.dart +++ b/lib/src/winrt/gaming/input/igamepadstatics.dart @@ -115,24 +115,27 @@ class IGamepadStatics extends IInspectable { List get gamepads { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(10) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IVectorView.fromRawPointer(retValuePtr, - iterableIid: '{47132ba0-6b17-5cd2-a8bd-b5d3443ccb13}', - creator: Gamepad.fromRawPointer) - .toList(); - } finally { + final hr = ptr.ref.vtable + .elementAt(10) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final vectorView = IVectorView.fromRawPointer(retValuePtr, + iterableIid: '{47132ba0-6b17-5cd2-a8bd-b5d3443ccb13}', + creator: Gamepad.fromRawPointer); + final list = vectorView.toList(); + vectorView.release(); + + return list; } } diff --git a/lib/src/winrt/globalization/calendar.dart b/lib/src/winrt/globalization/calendar.dart index e50fac3f6f..2401ed8df3 100644 --- a/lib/src/winrt/globalization/calendar.dart +++ b/lib/src/winrt/globalization/calendar.dart @@ -34,8 +34,7 @@ import 'itimezoneoncalendar.dart'; /// {@category Class} /// {@category winrt} class Calendar extends IInspectable implements ICalendar, ITimeZoneOnCalendar { - Calendar({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + Calendar() : super(ActivateClass(_className)); Calendar.fromRawPointer(super.ptr); static const _className = 'Windows.Globalization.Calendar'; @@ -43,41 +42,42 @@ class Calendar extends IInspectable implements ICalendar, ITimeZoneOnCalendar { // ICalendarFactory methods static Calendar createCalendarDefaultCalendarAndClock( IIterable languages) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_ICalendarFactory); + final object = ICalendarFactory.fromRawPointer(activationFactoryPtr); try { - return ICalendarFactory.fromRawPointer(activationFactory) - .createCalendarDefaultCalendarAndClock(languages); + return object.createCalendarDefaultCalendarAndClock(languages); } finally { - free(activationFactory); + object.release(); } } static Calendar createCalendar( IIterable languages, String calendar, String clock) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_ICalendarFactory); + final object = ICalendarFactory.fromRawPointer(activationFactoryPtr); try { - return ICalendarFactory.fromRawPointer(activationFactory) - .createCalendar(languages, calendar, clock); + return object.createCalendar(languages, calendar, clock); } finally { - free(activationFactory); + object.release(); } } // ICalendarFactory2 methods static Calendar createCalendarWithTimeZone(IIterable languages, String calendar, String clock, String timeZoneId) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_ICalendarFactory2); + final object = ICalendarFactory2.fromRawPointer(activationFactoryPtr); try { - return ICalendarFactory2.fromRawPointer(activationFactory) - .createCalendarWithTimeZone(languages, calendar, clock, timeZoneId); + return object.createCalendarWithTimeZone( + languages, calendar, clock, timeZoneId); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/globalization/icalendar.dart b/lib/src/winrt/globalization/icalendar.dart index 4a0e81b1a7..6359509cb2 100644 --- a/lib/src/winrt/globalization/icalendar.dart +++ b/lib/src/winrt/globalization/icalendar.dart @@ -80,24 +80,27 @@ class ICalendar extends IInspectable { List get languages { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); + final hr = ptr.ref.vtable + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); - return IVectorView.fromRawPointer(retValuePtr, - iterableIid: '{e2fcc7c1-3bfc-5a0b-b2b0-72e769d1cb7e}') - .toList(); - } finally { + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final vectorView = IVectorView.fromRawPointer(retValuePtr, + iterableIid: '{e2fcc7c1-3bfc-5a0b-b2b0-72e769d1cb7e}'); + final list = vectorView.toList(); + vectorView.release(); + + return list; } String get numeralSystem { @@ -166,6 +169,7 @@ class ICalendar extends IInspectable { void changeCalendarSystem(String value) { final valueHstring = convertToHString(value); + final hr = ptr.ref.vtable .elementAt(13) .cast< @@ -175,6 +179,7 @@ class ICalendar extends IInspectable { int Function(Pointer, int value)>()(ptr.ref.lpVtbl, valueHstring); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(valueHstring); } @@ -204,6 +209,7 @@ class ICalendar extends IInspectable { void changeClock(String value) { final valueHstring = convertToHString(value); + final hr = ptr.ref.vtable .elementAt(15) .cast< @@ -213,6 +219,7 @@ class ICalendar extends IInspectable { int Function(Pointer, int value)>()(ptr.ref.lpVtbl, valueHstring); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(valueHstring); } @@ -242,6 +249,7 @@ class ICalendar extends IInspectable { void setDateTime(DateTime value) { final valueDateTime = value.difference(DateTime.utc(1601, 01, 01)).inMicroseconds * 10; + final hr = ptr.ref.vtable .elementAt(17) .cast< diff --git a/lib/src/winrt/globalization/icalendarfactory.dart b/lib/src/winrt/globalization/icalendarfactory.dart index 37cd67966c..e3110d7a9a 100644 --- a/lib/src/winrt/globalization/icalendarfactory.dart +++ b/lib/src/winrt/globalization/icalendarfactory.dart @@ -66,6 +66,7 @@ class ICalendarFactory extends IInspectable { final calendarHstring = convertToHString(calendar); final clockHstring = convertToHString(clock); + final hr = ptr.ref.vtable .elementAt(7) @@ -95,6 +96,7 @@ class ICalendarFactory extends IInspectable { WindowsDeleteString(calendarHstring); WindowsDeleteString(clockHstring); + return Calendar.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/globalization/icalendarfactory2.dart b/lib/src/winrt/globalization/icalendarfactory2.dart index 22d5edac45..9dc33677ff 100644 --- a/lib/src/winrt/globalization/icalendarfactory2.dart +++ b/lib/src/winrt/globalization/icalendarfactory2.dart @@ -43,6 +43,7 @@ class ICalendarFactory2 extends IInspectable { final calendarHstring = convertToHString(calendar); final clockHstring = convertToHString(clock); final timeZoneIdHstring = convertToHString(timeZoneId); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -79,6 +80,7 @@ class ICalendarFactory2 extends IInspectable { WindowsDeleteString(calendarHstring); WindowsDeleteString(clockHstring); WindowsDeleteString(timeZoneIdHstring); + return Calendar.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/globalization/itimezoneoncalendar.dart b/lib/src/winrt/globalization/itimezoneoncalendar.dart index 256019b77e..c87bad3cf0 100644 --- a/lib/src/winrt/globalization/itimezoneoncalendar.dart +++ b/lib/src/winrt/globalization/itimezoneoncalendar.dart @@ -60,6 +60,7 @@ class ITimeZoneOnCalendar extends IInspectable { void changeTimeZone(String timeZoneId) { final timeZoneIdHstring = convertToHString(timeZoneId); + final hr = ptr.ref.vtable .elementAt(7) .cast< @@ -71,6 +72,7 @@ class ITimeZoneOnCalendar extends IInspectable { Pointer, int timeZoneId)>()(ptr.ref.lpVtbl, timeZoneIdHstring); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(timeZoneIdHstring); } diff --git a/lib/src/winrt/globalization/phonenumberformatting/iphonenumberformatterstatics.dart b/lib/src/winrt/globalization/phonenumberformatting/iphonenumberformatterstatics.dart index aafdab84e4..70333c78c6 100644 --- a/lib/src/winrt/globalization/phonenumberformatting/iphonenumberformatterstatics.dart +++ b/lib/src/winrt/globalization/phonenumberformatting/iphonenumberformatterstatics.dart @@ -53,6 +53,7 @@ class IPhoneNumberFormatterStatics extends IInspectable { ptr.ref.lpVtbl, regionCodeHstring, phoneNumber.ptr); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(regionCodeHstring); } diff --git a/lib/src/winrt/globalization/phonenumberformatting/iphonenumberinfofactory.dart b/lib/src/winrt/globalization/phonenumberformatting/iphonenumberinfofactory.dart index fb95c93a12..0b052495aa 100644 --- a/lib/src/winrt/globalization/phonenumberformatting/iphonenumberinfofactory.dart +++ b/lib/src/winrt/globalization/phonenumberformatting/iphonenumberinfofactory.dart @@ -38,6 +38,7 @@ class IPhoneNumberInfoFactory extends IInspectable { PhoneNumberInfo create(String number) { final retValuePtr = calloc(); final numberHstring = convertToHString(number); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -54,7 +55,9 @@ class IPhoneNumberInfoFactory extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(numberHstring); + return PhoneNumberInfo.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/globalization/phonenumberformatting/phonenumberformatter.dart b/lib/src/winrt/globalization/phonenumberformatting/phonenumberformatter.dart index 30ce2f683a..ccab66654b 100644 --- a/lib/src/winrt/globalization/phonenumberformatting/phonenumberformatter.dart +++ b/lib/src/winrt/globalization/phonenumberformatting/phonenumberformatter.dart @@ -31,8 +31,7 @@ import 'phonenumberinfo.dart'; /// {@category winrt} class PhoneNumberFormatter extends IInspectable implements IPhoneNumberFormatter { - PhoneNumberFormatter({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + PhoneNumberFormatter() : super(ActivateClass(_className)); PhoneNumberFormatter.fromRawPointer(super.ptr); static const _className = @@ -40,51 +39,56 @@ class PhoneNumberFormatter extends IInspectable // IPhoneNumberFormatterStatics methods static void tryCreate(String regionCode, PhoneNumberFormatter phoneNumber) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberFormatterStatics); + final object = + IPhoneNumberFormatterStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberFormatterStatics.fromRawPointer(activationFactory) - .tryCreate(regionCode, phoneNumber); + return object.tryCreate(regionCode, phoneNumber); } finally { - free(activationFactory); + object.release(); } } static int getCountryCodeForRegion(String regionCode) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberFormatterStatics); + final object = + IPhoneNumberFormatterStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberFormatterStatics.fromRawPointer(activationFactory) - .getCountryCodeForRegion(regionCode); + return object.getCountryCodeForRegion(regionCode); } finally { - free(activationFactory); + object.release(); } } static String getNationalDirectDialingPrefixForRegion( String regionCode, bool stripNonDigit) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberFormatterStatics); + final object = + IPhoneNumberFormatterStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberFormatterStatics.fromRawPointer(activationFactory) - .getNationalDirectDialingPrefixForRegion(regionCode, stripNonDigit); + return object.getNationalDirectDialingPrefixForRegion( + regionCode, stripNonDigit); } finally { - free(activationFactory); + object.release(); } } static String wrapWithLeftToRightMarkers(String number) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberFormatterStatics); + final object = + IPhoneNumberFormatterStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberFormatterStatics.fromRawPointer(activationFactory) - .wrapWithLeftToRightMarkers(number); + return object.wrapWithLeftToRightMarkers(number); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/globalization/phonenumberformatting/phonenumberinfo.dart b/lib/src/winrt/globalization/phonenumberformatting/phonenumberinfo.dart index e253314cf1..a1cdff3a03 100644 --- a/lib/src/winrt/globalization/phonenumberformatting/phonenumberinfo.dart +++ b/lib/src/winrt/globalization/phonenumberformatting/phonenumberinfo.dart @@ -39,41 +39,41 @@ class PhoneNumberInfo extends IInspectable // IPhoneNumberInfoFactory methods static PhoneNumberInfo create(String number) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberInfoFactory); + final object = IPhoneNumberInfoFactory.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberInfoFactory.fromRawPointer(activationFactory) - .create(number); + return object.create(number); } finally { - free(activationFactory); + object.release(); } } // IPhoneNumberInfoStatics methods static PhoneNumberParseResult tryParse( String input, PhoneNumberInfo phoneNumber) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberInfoStatics); + final object = IPhoneNumberInfoStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberInfoStatics.fromRawPointer(activationFactory) - .tryParse(input, phoneNumber); + return object.tryParse(input, phoneNumber); } finally { - free(activationFactory); + object.release(); } } static PhoneNumberParseResult tryParseWithRegion( String input, String regionCode, PhoneNumberInfo phoneNumber) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IPhoneNumberInfoStatics); + final object = IPhoneNumberInfoStatics.fromRawPointer(activationFactoryPtr); try { - return IPhoneNumberInfoStatics.fromRawPointer(activationFactory) - .tryParseWithRegion(input, regionCode, phoneNumber); + return object.tryParseWithRegion(input, regionCode, phoneNumber); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/graphics/printing3d/printing3dmultiplepropertymaterial.dart b/lib/src/winrt/graphics/printing3d/printing3dmultiplepropertymaterial.dart index 91985351df..9da8df0d9a 100644 --- a/lib/src/winrt/graphics/printing3d/printing3dmultiplepropertymaterial.dart +++ b/lib/src/winrt/graphics/printing3d/printing3dmultiplepropertymaterial.dart @@ -30,8 +30,7 @@ import 'iprinting3dmultiplepropertymaterial.dart'; /// {@category winrt} class Printing3DMultiplePropertyMaterial extends IInspectable implements IPrinting3DMultiplePropertyMaterial { - Printing3DMultiplePropertyMaterial({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + Printing3DMultiplePropertyMaterial() : super(ActivateClass(_className)); Printing3DMultiplePropertyMaterial.fromRawPointer(super.ptr); static const _className = diff --git a/lib/src/winrt/media/mediaproperties/mediapropertyset.dart b/lib/src/winrt/media/mediaproperties/mediapropertyset.dart index 28c3dab0d8..885b3a36fd 100644 --- a/lib/src/winrt/media/mediaproperties/mediapropertyset.dart +++ b/lib/src/winrt/media/mediaproperties/mediapropertyset.dart @@ -33,8 +33,7 @@ import '../../internal/hstring_array.dart'; /// {@category winrt} class MediaPropertySet extends IInspectable implements IMap, IIterable> { - MediaPropertySet({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + MediaPropertySet() : super(ActivateClass(_className)); MediaPropertySet.fromRawPointer(super.ptr); static const _className = 'Windows.Media.MediaProperties.MediaPropertySet'; diff --git a/lib/src/winrt/networking/connectivity/iipinformation.dart b/lib/src/winrt/networking/connectivity/iipinformation.dart index 0ce5d435ad..f3a6ef76d5 100644 --- a/lib/src/winrt/networking/connectivity/iipinformation.dart +++ b/lib/src/winrt/networking/connectivity/iipinformation.dart @@ -60,23 +60,28 @@ class IIPInformation extends IInspectable { int? get prefixLength { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(7) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); - - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{e5198cc8-2873-55f5-b0a1-84ff9e4aad62}') - .value; - } finally { + final hr = ptr.ref.vtable + .elementAt(7) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{e5198cc8-2873-55f5-b0a1-84ff9e4aad62}'); + final value = reference.value; + reference.release(); + + return value; } } diff --git a/lib/src/winrt/networking/connectivity/inetworkinformationstatics.dart b/lib/src/winrt/networking/connectivity/inetworkinformationstatics.dart index 31d1796c0f..a15fa2d888 100644 --- a/lib/src/winrt/networking/connectivity/inetworkinformationstatics.dart +++ b/lib/src/winrt/networking/connectivity/inetworkinformationstatics.dart @@ -8,22 +8,26 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; -import '../../../callbacks.dart'; import '../../../com/iinspectable.dart'; import '../../../combase.dart'; -import '../../../constants.dart'; import '../../../exceptions.dart'; -import '../../../guid.dart'; import '../../../macros.dart'; -import '../../../structs.g.dart'; import '../../../types.dart'; import '../../../utils.dart'; -import '../../../variant.dart'; import '../../../win32/api_ms_win_core_winrt_string_l1_1_0.g.dart'; -import '../../../win32/ole32.g.dart'; -import '../../../winrt/foundation/collections/ivectorview.dart'; -import '../../../winrt/networking/ihostname.dart'; +import '../../../winrt_callbacks.dart'; import '../../../winrt_helpers.dart'; +import '../../foundation/collections/iiterable.dart'; +import '../../foundation/collections/ivectorview.dart'; +import '../../foundation/iasyncoperation.dart'; +import '../../foundation/uri.dart' as winrt_uri; +import '../../internal/hstring_array.dart'; +// import '../endpointpair.dart'; +import '../enums.g.dart'; +import '../hostname.dart'; +import 'connectionprofile.dart'; +// import 'lanidentifier.dart'; +// import 'proxyconfiguration.dart'; /// @nodoc const IID_INetworkInformationStatics = '{5074f851-950d-4165-9c15-365619481eea}'; @@ -42,25 +46,19 @@ class INetworkInformationStatics extends IInspectable { final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(6) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer, - )>()( - ptr.ref.lpVtbl, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); + .elementAt(6) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { + free(retValuePtr); + throw WindowsException(hr); + } return retValuePtr; } @@ -69,25 +67,19 @@ class INetworkInformationStatics extends IInspectable { final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(7) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer, - )>()( - ptr.ref.lpVtbl, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); + .elementAt(7) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { + free(retValuePtr); + throw WindowsException(hr); + } return retValuePtr; } @@ -96,91 +88,75 @@ class INetworkInformationStatics extends IInspectable { final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(8) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer, - )>()( - ptr.ref.lpVtbl, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); + .elementAt(8) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { + free(retValuePtr); + throw WindowsException(hr); + } return retValuePtr; } - List getHostNames() { + List getHostNames() { final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer, - )>()( - ptr.ref.lpVtbl, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); - - try { - return IVectorView.fromRawPointer(retValuePtr, - iterableIid: '{9e5f3ed0-cf1c-5d38-832c-acea6164bf5c}', - creator: IHostName.fromRawPointer) - .toList(); - } finally { + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); + + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final vectorView = IVectorView.fromRawPointer(retValuePtr, + iterableIid: '{9e5f3ed0-cf1c-5d38-832c-acea6164bf5c}', + creator: HostName.fromRawPointer); + final list = vectorView.toList(); + vectorView.release(); + + return list; } - Pointer getProxyConfigurationAsync( - Pointer uri, - ) { + Pointer getProxyConfigurationAsync(Uri uri) { final retValuePtr = calloc(); + final uriUri = winrt_uri.Uri.createUri(uri.toString()); final hr = ptr.ref.vtable - .elementAt(10) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer uri, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer uri, - Pointer, - )>()( - ptr.ref.lpVtbl, - uri.cast>().value, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); + .elementAt(10) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer uri, + Pointer)>>>() + .value + .asFunction< + int Function( + Pointer, Pointer uri, Pointer)>()( + ptr.ref.lpVtbl, + uriUri.ptr.cast>().value, + retValuePtr); + + if (FAILED(hr)) { + free(retValuePtr); + throw WindowsException(hr); + } + + uriUri.release(); return retValuePtr; } @@ -192,94 +168,79 @@ class INetworkInformationStatics extends IInspectable { final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(11) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer destinationList, - Uint32 sortOptions, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer destinationList, - int sortOptions, - Pointer, - )>()( - ptr.ref.lpVtbl, - destinationList.cast>().value, - sortOptions, - retValuePtr, - ); - - if (FAILED(hr)) throw WindowsException(hr); + .elementAt(11) + .cast< + Pointer< + NativeFunction< + HRESULT Function( + Pointer, + Pointer destinationList, + Uint32 sortOptions, + Pointer)>>>() + .value + .asFunction< + int Function(Pointer, Pointer destinationList, + int sortOptions, Pointer)>()( + ptr.ref.lpVtbl, + destinationList.cast>().value, + sortOptions, + retValuePtr); + + if (FAILED(hr)) { + free(retValuePtr); + throw WindowsException(hr); + } return retValuePtr; } - // EventRegistrationToken add_NetworkStatusChanged( - // Pointer> - // networkStatusHandler, - // ) { - // final retValuePtr = calloc(); + // int add_NetworkStatusChanged( + // Pointer> + // networkStatusHandler) { + // final retValuePtr = calloc(); // try { // final hr = ptr.ref.vtable - // .elementAt(12) - // .cast< - // Pointer< - // NativeFunction< - // HRESULT Function( - // Pointer, - // Pointer> - // networkStatusHandler, - // Pointer, - // )>>>() - // .value - // .asFunction< - // int Function( - // Pointer, - // Pointer> - // networkStatusHandler, - // Pointer, - // )>()( - // ptr.ref.lpVtbl, - // networkStatusHandler, - // retValuePtr, - // ); + // .elementAt(12) + // .cast< + // Pointer< + // NativeFunction< + // HRESULT Function( + // Pointer, + // Pointer< + // NativeFunction< + // NetworkStatusChangedEventHandler>> + // networkStatusHandler, + // Pointer)>>>() + // .value + // .asFunction< + // int Function( + // Pointer, + // Pointer> + // networkStatusHandler, + // Pointer)>()( + // ptr.ref.lpVtbl, networkStatusHandler, retValuePtr); // if (FAILED(hr)) throw WindowsException(hr); - // final retValue = retValuePtr.ref; + // final retValue = retValuePtr.value; // return retValue; // } finally { // free(retValuePtr); // } // } - // void remove_NetworkStatusChanged( - // EventRegistrationToken eventCookie, - // ) => - // ptr.ref.vtable - // .elementAt(13) - // .cast< - // Pointer< - // NativeFunction< - // HRESULT Function( - // Pointer, - // EventRegistrationToken eventCookie, - // )>>>() - // .value - // .asFunction< - // int Function( - // Pointer, - // EventRegistrationToken eventCookie, - // )>()( - // ptr.ref.lpVtbl, - // eventCookie, - // ); + // void remove_NetworkStatusChanged(int eventCookie) { + // final hr = ptr.ref.vtable + // .elementAt(13) + // .cast< + // Pointer< + // NativeFunction< + // HRESULT Function(Pointer, IntPtr eventCookie)>>>() + // .value + // .asFunction()( + // ptr.ref.lpVtbl, eventCookie); + + // if (FAILED(hr)) throw WindowsException(hr); + // } } diff --git a/lib/src/winrt/networking/hostname.dart b/lib/src/winrt/networking/hostname.dart index d4d44d87da..1af8e4a327 100644 --- a/lib/src/winrt/networking/hostname.dart +++ b/lib/src/winrt/networking/hostname.dart @@ -38,27 +38,27 @@ class HostName extends IInspectable implements IHostName, IStringable { // IHostNameFactory methods static HostName createHostName(String hostName) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IHostNameFactory); + final object = IHostNameFactory.fromRawPointer(activationFactoryPtr); try { - return IHostNameFactory.fromRawPointer(activationFactory) - .createHostName(hostName); + return object.createHostName(hostName); } finally { - free(activationFactory); + object.release(); } } // IHostNameStatics methods static int compare(String value1, String value2) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IHostNameStatics); + final object = IHostNameStatics.fromRawPointer(activationFactoryPtr); try { - return IHostNameStatics.fromRawPointer(activationFactory) - .compare(value1, value2); + return object.compare(value1, value2); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/networking/ihostnamefactory.dart b/lib/src/winrt/networking/ihostnamefactory.dart index 46e56ff69f..763a72729d 100644 --- a/lib/src/winrt/networking/ihostnamefactory.dart +++ b/lib/src/winrt/networking/ihostnamefactory.dart @@ -38,6 +38,7 @@ class IHostNameFactory extends IInspectable { HostName createHostName(String hostName) { final retValuePtr = calloc(); final hostNameHstring = convertToHString(hostName); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -54,7 +55,9 @@ class IHostNameFactory extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(hostNameHstring); + return HostName.fromRawPointer(retValuePtr); } } diff --git a/lib/src/winrt/storage/istorageitem.dart b/lib/src/winrt/storage/istorageitem.dart index 1477a97ae1..c03cedcb4b 100644 --- a/lib/src/winrt/storage/istorageitem.dart +++ b/lib/src/winrt/storage/istorageitem.dart @@ -43,6 +43,7 @@ class IStorageItem extends IInspectable { Pointer renameAsyncOverloadDefaultOptions(String desiredName) { final retValuePtr = calloc(); final desiredNameHstring = convertToHString(desiredName); + final hr = ptr.ref.vtable .elementAt(6) .cast< @@ -59,7 +60,9 @@ class IStorageItem extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(desiredNameHstring); + return retValuePtr; } @@ -86,6 +89,7 @@ class IStorageItem extends IInspectable { free(retValuePtr); throw WindowsException(hr); } + WindowsDeleteString(desiredNameHstring); return retValuePtr; diff --git a/lib/src/winrt/storage/pickers/fileopenpicker.dart b/lib/src/winrt/storage/pickers/fileopenpicker.dart index 162e28e2c4..0b4365eb19 100644 --- a/lib/src/winrt/storage/pickers/fileopenpicker.dart +++ b/lib/src/winrt/storage/pickers/fileopenpicker.dart @@ -40,22 +40,21 @@ import 'ifileopenpickerstatics2.dart'; /// {@category winrt} class FileOpenPicker extends IInspectable implements IFileOpenPicker, IFileOpenPicker3 { - FileOpenPicker({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + FileOpenPicker() : super(ActivateClass(_className)); FileOpenPicker.fromRawPointer(super.ptr); static const _className = 'Windows.Storage.Pickers.FileOpenPicker'; // IFileOpenPickerStatics2 methods static FileOpenPicker createForUser(User user) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IFileOpenPickerStatics2); + final object = IFileOpenPickerStatics2.fromRawPointer(activationFactoryPtr); try { - return IFileOpenPickerStatics2.fromRawPointer(activationFactory) - .createForUser(user); + return object.createForUser(user); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/storage/userdatapaths.dart b/lib/src/winrt/storage/userdatapaths.dart index ddf3df3ef4..486f114a38 100644 --- a/lib/src/winrt/storage/userdatapaths.dart +++ b/lib/src/winrt/storage/userdatapaths.dart @@ -36,26 +36,26 @@ class UserDataPaths extends IInspectable implements IUserDataPaths { // IUserDataPathsStatics methods static UserDataPaths getForUser(User user) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUserDataPathsStatics); + final object = IUserDataPathsStatics.fromRawPointer(activationFactoryPtr); try { - return IUserDataPathsStatics.fromRawPointer(activationFactory) - .getForUser(user); + return object.getForUser(user); } finally { - free(activationFactory); + object.release(); } } static UserDataPaths getDefault() { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IUserDataPathsStatics); + final object = IUserDataPathsStatics.fromRawPointer(activationFactoryPtr); try { - return IUserDataPathsStatics.fromRawPointer(activationFactory) - .getDefault(); + return object.getDefault(); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/ui/notifications/itoastnotification.dart b/lib/src/winrt/ui/notifications/itoastnotification.dart index d84e5c7a09..917e6e7319 100644 --- a/lib/src/winrt/ui/notifications/itoastnotification.dart +++ b/lib/src/winrt/ui/notifications/itoastnotification.dart @@ -58,7 +58,9 @@ class IToastNotification extends IInspectable { } set expirationTime(DateTime? value) { - final referencePtr = boxValue(value, convertToIReference: true); + final referencePtr = value == null + ? calloc() + : boxValue(value, convertToIReference: true); final hr = ptr.ref.vtable .elementAt(7) @@ -70,30 +72,35 @@ class IToastNotification extends IInspectable { if (FAILED(hr)) throw WindowsException(hr); - free(referencePtr); + if (value == null) free(referencePtr); } DateTime? get expirationTime { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(8) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); + final hr = ptr.ref.vtable + .elementAt(8) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); - return IReference.fromRawPointer(retValuePtr, - referenceIid: '{5541d8a7-497c-5aa4-86fc-7713adbf2a2c}') - .value; - } finally { + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + if (retValuePtr.ref.lpVtbl == nullptr) return null; + + final reference = IReference.fromRawPointer(retValuePtr, + referenceIid: '{5541d8a7-497c-5aa4-86fc-7713adbf2a2c}'); + final value = reference.value; + reference.release(); + + return value; } int add_Dismissed(Pointer> handler) { diff --git a/lib/src/winrt/ui/notifications/notificationdata.dart b/lib/src/winrt/ui/notifications/notificationdata.dart index 611ab294e8..8c588e0bb0 100644 --- a/lib/src/winrt/ui/notifications/notificationdata.dart +++ b/lib/src/winrt/ui/notifications/notificationdata.dart @@ -31,8 +31,7 @@ import 'inotificationdatafactory.dart'; /// {@category Class} /// {@category winrt} class NotificationData extends IInspectable implements INotificationData { - NotificationData({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + NotificationData() : super(ActivateClass(_className)); NotificationData.fromRawPointer(super.ptr); static const _className = 'Windows.UI.Notifications.NotificationData'; @@ -41,28 +40,30 @@ class NotificationData extends IInspectable implements INotificationData { static NotificationData createNotificationDataWithValuesAndSequenceNumber( IIterable> initialValues, int sequenceNumber) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_INotificationDataFactory); + final object = + INotificationDataFactory.fromRawPointer(activationFactoryPtr); try { - return INotificationDataFactory.fromRawPointer(activationFactory) - .createNotificationDataWithValuesAndSequenceNumber( - initialValues, sequenceNumber); + return object.createNotificationDataWithValuesAndSequenceNumber( + initialValues, sequenceNumber); } finally { - free(activationFactory); + object.release(); } } static NotificationData createNotificationDataWithValues( IIterable> initialValues) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_INotificationDataFactory); + final object = + INotificationDataFactory.fromRawPointer(activationFactoryPtr); try { - return INotificationDataFactory.fromRawPointer(activationFactory) - .createNotificationDataWithValues(initialValues); + return object.createNotificationDataWithValues(initialValues); } finally { - free(activationFactory); + object.release(); } } diff --git a/lib/src/winrt/ui/notifications/toastnotification.dart b/lib/src/winrt/ui/notifications/toastnotification.dart index 9a3b74897c..82e1c0470a 100644 --- a/lib/src/winrt/ui/notifications/toastnotification.dart +++ b/lib/src/winrt/ui/notifications/toastnotification.dart @@ -20,6 +20,7 @@ import '../../../winrt_helpers.dart'; import '../../data/xml/dom/xmldocument.dart'; import '../../foundation/ireference.dart'; import '../../internal/hstring_array.dart'; +import '../../internal/ipropertyvalue_helpers.dart'; import 'enums.g.dart'; import 'itoastnotification.dart'; import 'itoastnotification2.dart'; @@ -29,6 +30,9 @@ import 'itoastnotification6.dart'; import 'itoastnotificationfactory.dart'; import 'notificationdata.dart'; +/// Defines the content, associated metadata and events, and expiration time +/// of a toast notification. +/// /// {@category Class} /// {@category winrt} class ToastNotification extends IInspectable @@ -44,15 +48,16 @@ class ToastNotification extends IInspectable // IToastNotificationFactory methods static ToastNotification createToastNotification(Pointer content) { - final activationFactory = + final activationFactoryPtr = CreateActivationFactory(_className, IID_IToastNotificationFactory); + final object = + IToastNotificationFactory.fromRawPointer(activationFactoryPtr); try { - final result = IToastNotificationFactory.fromRawPointer(activationFactory) - .createToastNotification(content); + final result = object.createToastNotification(content); return ToastNotification.fromRawPointer(result); } finally { - free(activationFactory); + object.release(); } } @@ -91,6 +96,7 @@ class ToastNotification extends IInspectable @override void remove_Failed(int token) => _iToastNotification.remove_Failed(token); + // IToastNotification2 methods late final _iToastNotification2 = IToastNotification2.from(this); @@ -111,6 +117,7 @@ class ToastNotification extends IInspectable @override bool get suppressPopup => _iToastNotification2.suppressPopup; + // IToastNotification3 methods late final _iToastNotification3 = IToastNotification3.from(this); @@ -127,6 +134,7 @@ class ToastNotification extends IInspectable @override set remoteId(String value) => _iToastNotification3.remoteId = value; + // IToastNotification4 methods late final _iToastNotification4 = IToastNotification4.from(this); @@ -142,6 +150,7 @@ class ToastNotification extends IInspectable @override set priority(ToastNotificationPriority value) => _iToastNotification4.priority = value; + // IToastNotification6 methods late final _iToastNotification6 = IToastNotification6.from(this); diff --git a/lib/src/winrt/ui/viewmanagement/uisettings.dart b/lib/src/winrt/ui/viewmanagement/uisettings.dart index a56c787e0a..851bc3960d 100644 --- a/lib/src/winrt/ui/viewmanagement/uisettings.dart +++ b/lib/src/winrt/ui/viewmanagement/uisettings.dart @@ -42,8 +42,7 @@ class UISettings extends IInspectable IUISettings4, IUISettings5, IUISettings6 { - UISettings({Allocator allocator = calloc}) - : super(ActivateClass(_className, allocator: allocator)); + UISettings() : super(ActivateClass(_className)); UISettings.fromRawPointer(super.ptr); static const _className = 'Windows.UI.ViewManagement.UISettings'; From 23ca4e55e5ee64b9c640e178952bf19a64f96b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 16 Dec 2022 18:57:10 +0300 Subject: [PATCH 15/17] Fix tests --- test/com_network_test.dart | 19 +-- test/com_test.dart | 39 +++-- test/winrt_calendar_test.dart | 47 +++--- test/winrt_collections_test.dart | 157 ++++++++---------- test/winrt_ireference_test.dart | 60 ++++++- test/winrt_phonenumberformatter_test.dart | 6 +- test/winrt_propertyvalue_test.dart | 34 +++- test/winrt_test.dart | 26 ++- test/winrt_uri_test.dart | 7 +- tool/generator/test/goldens/icalendar.golden | 38 +++-- .../generator/test/winrt_projection_test.dart | 24 +-- 11 files changed, 261 insertions(+), 196 deletions(-) diff --git a/test/com_network_test.dart b/test/com_network_test.dart index ed08f51d6c..8ccebd57c7 100644 --- a/test/com_network_test.dart +++ b/test/com_network_test.dart @@ -16,8 +16,7 @@ void main() { final nlm = NetworkListManager.createInstance(); expect(nlm.ptr.address, isNonZero); - free(nlm.ptr); - + nlm.release(); CoUninitialize(); }); @@ -31,14 +30,14 @@ void main() { test('Network is connected', () { final nlm = NetworkListManager.createInstance(); expect(nlm.isConnected, equals(VARIANT_TRUE)); - free(nlm.ptr); + nlm.release(); }); test('Network is connected to the internet', () { for (var i = 0; i < testRuns; i++) { final nlm = NetworkListManager.createInstance(); expect(nlm.isConnectedToInternet, equals(VARIANT_TRUE)); - free(nlm.ptr); + nlm.release(); } }); @@ -61,9 +60,9 @@ void main() { expect(network.isConnected, anyOf(equals(VARIANT_TRUE), equals(VARIANT_FALSE))); - free(netPtr); - free(enumPtr); - free(nlm.ptr); + network.release(); + enumerator.release(); + nlm.release(); }); test('First network connection has a description', () { @@ -87,9 +86,9 @@ void main() { // more than one character long, and test for that. expect(descPtr.value.length, greaterThan(1)); - free(netPtr); - free(enumPtr); - free(nlm.ptr); + network.release(); + enumerator.release(); + nlm.release(); }); tearDown(CoUninitialize); diff --git a/test/com_test.dart b/test/com_test.dart index ff6b2f8405..702e05b85f 100644 --- a/test/com_test.dart +++ b/test/com_test.dart @@ -111,7 +111,7 @@ void main() { free(iidClassFactory); free(clsid); free(ptrSaveDialog); - free(ptrFactory); + classFactory.release(); CoUninitialize(); }); @@ -128,6 +128,7 @@ void main() { group('COM object tests', () { late FileOpenDialog dialog; + setUp(() { final hr = CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); @@ -135,32 +136,27 @@ void main() { dialog = FileOpenDialog.createInstance(); }); + test('Dialog object exists', () { expect(dialog.ptr.address, isNonZero); }); - test('Can cast to IUnknown', () { - final riid = convertToIID(IID_IUnknown); - - final classPtr = calloc(); - final hr = dialog.queryInterface(riid.cast(), classPtr); - expect(hr, equals(S_OK)); - final unk = IUnknown(classPtr.cast()); + test('Can cast to IUnknown', () { + final unk = IUnknown.from(dialog); expect(unk.ptr.address, isNonZero); - free(classPtr); - free(riid); + unk.release(); }); - test('Cast to random interface fails', () { - final riid = convertToIID(IID_IDesktopWallpaper); - - final classPtr = calloc(); - final hr = dialog.queryInterface(riid.cast(), classPtr); - expect(hr, equals(E_NOINTERFACE)); - free(classPtr); - free(riid); + test('Cast to random interface fails', () { + expect( + () => dialog.toInterface(IID_IDesktopWallpaper), + throwsA(isA() + .having((e) => e.hr, 'hr', equals(E_NOINTERFACE)) + .having((e) => e.toString(), 'message', + contains('No such interface supported')))); }); + test('AddRef / Release', () { var refs = dialog.addRef(); expect(refs, equals(2)); @@ -174,14 +170,16 @@ void main() { refs = dialog.release(); expect(refs, equals(1)); }); + tearDown(() { - free(dialog.ptr); + dialog.release(); CoUninitialize(); }); }); group('COM object casting using methods', () { late FileOpenDialog dialog; + setUp(() { final hr = CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); @@ -189,6 +187,7 @@ void main() { dialog = FileOpenDialog.createInstance(); }); + test('Can cast to various supported interfaces', () { expect(() => IUnknown.from(dialog), returnsNormally); expect(() => IModalWindow.from(dialog), returnsNormally); @@ -209,7 +208,7 @@ void main() { }); tearDown(() { - free(dialog.ptr); + dialog.release(); CoUninitialize(); }); }); diff --git a/test/winrt_calendar_test.dart b/test/winrt_calendar_test.dart index 8f2bcb3de3..2b5dde0c0d 100644 --- a/test/winrt_calendar_test.dart +++ b/test/winrt_calendar_test.dart @@ -1,5 +1,3 @@ -// ignore_for_file: constant_identifier_names - @TestOn('windows') import 'package:test/test.dart'; @@ -10,11 +8,10 @@ import 'package:win32/winrt.dart'; void main() { if (isWindowsRuntimeAvailable()) { - late ICalendar calendar; + late Calendar calendar; setUp(() { winrtInitialize(); - calendar = Calendar(); }); @@ -30,6 +27,8 @@ void main() { expect( calendar2.runtimeClassName, equals('Windows.Globalization.Calendar')); expect(calendar2.year, equals(calendar.year)); + + calendar2.release(); }); test('Calendar.setToMin', () { @@ -37,6 +36,8 @@ void main() { calendar.setToMin(); expect(calendar.compare(today), isNegative); + + today.release(); }); test('Calendar.setToMax', () { @@ -44,11 +45,14 @@ void main() { calendar.setToMax(); expect(calendar.compare(today), isPositive); + + today.release(); }); test('Calendar.languages', () { - expect(calendar.languages.length, isPositive); - expect(calendar.languages.first, contains('-')); // e.g. en-US + final languages = calendar.languages; + expect(languages.length, isPositive); + expect(languages.first, contains('-')); // e.g. en-US }); test('Calendar.numeralSystem getter', () { @@ -166,7 +170,12 @@ void main() { expect(calendar.era, equals(4)); }); - test('Calendar.eraAsFullString', () { + test('Calendar.eraAsFullString (GregorianCalendar)', () { + calendar.changeCalendarSystem('GregorianCalendar'); + expect(calendar.eraAsFullString(), equals('A.D.')); + }); + + test('Calendar.eraAsFullString (JapaneseCalendar)', () { calendar ..changeCalendarSystem('JapaneseCalendar') ..era = 1 // 明治 (Meiji) @@ -234,10 +243,6 @@ void main() { expect(calendar.firstMonthInThisYear, equals(1)); }); - test('Calendar.firstMonthInThisYear getter', () { - expect(calendar.firstMonthInThisYear, equals(1)); - }); - test('Calendar.firstSecondInThisMinute getter', () { expect(calendar.firstSecondInThisMinute, equals(0)); }); @@ -329,15 +334,6 @@ void main() { expect(resolvedLanguage.length, equals(5)); }); - test('Calendar.numeralSystem getter', () { - final arabicNumerals = '٠١٢٣٤٥٦٧٨٩'.split(''); - calendar.numeralSystem = 'arab'; - final date = calendar.monthAsPaddedNumericString(2); - - expect(arabicNumerals, contains(date[0])); - expect(arabicNumerals, contains(date[1])); - }); - test('Calendar.period getter', () { calendar.changeClock('12HourClock'); expect(calendar.period, isIn([1, 2])); @@ -382,6 +378,8 @@ void main() { ..addDays(-1); final compare = calendar.compare(original); expect(compare, isZero); + + original.release(); }); test('Compare positive', () { @@ -391,6 +389,8 @@ void main() { ..addDays(-1); final compare = calendar.compare(original); expect(compare, isPositive); + + original.release(); }); test('Compare negative', () { @@ -400,11 +400,8 @@ void main() { ..addDays(-3); final compare = calendar.compare(original); expect(compare, isNegative); - }); - test('Calendar.eraAsFullString', () { - calendar.changeCalendarSystem('GregorianCalendar'); - expect(calendar.eraAsFullString(), equals('A.D.')); + original.release(); }); test('Calendar.monthAsFullString', () { @@ -470,7 +467,7 @@ void main() { // }); tearDown(() { - free(calendar.ptr); + calendar.release(); winrtUninitialize(); }); } diff --git a/test/winrt_collections_test.dart b/test/winrt_collections_test.dart index 738891d846..47cc6f2897 100644 --- a/test/winrt_collections_test.dart +++ b/test/winrt_collections_test.dart @@ -1,10 +1,11 @@ -// ignore_for_file: non_constant_identifier_names +@TestOn('windows') import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:test/test.dart'; import 'package:win32/src/winrt/foundation/uri.dart' as winrt_uri; +import 'package:win32/src/winrt/internal/comobject_pointer.dart'; import 'package:win32/winrt.dart'; // Exhaustively test the WinRT Collections to make sure constructors, @@ -33,7 +34,7 @@ void main() { map = IMap() ..insert(Guid.parse(IID_IFileOpenPicker), null) - ..insert(Guid.parse(IID_ICalendar), Calendar(allocator: allocator)) + ..insert(Guid.parse(IID_ICalendar), Calendar()) ..insert(Guid.parse(IID_IStorageItem), true) ..insert(Guid.parse(IID_IPhoneNumberFormatter), DateTime(2022, 7, 11, 17, 30)) @@ -53,9 +54,7 @@ void main() { const [Duration(hours: 1), Duration(minutes: 60)]) ..insert(Guid.parse(IID_IAppxManifestReader4), [Guid.parse(IID_IShellItem)]) - ..insert(Guid.parse(IID_IAppxManifestReader5), [ - Calendar(allocator: allocator), - ]) + ..insert(Guid.parse(IID_IAppxManifestReader5), [Calendar()]) ..insert(Guid.parse(IID_IAppxManifestReader6), [2022, -2022]) ..insert(Guid.parse(IID_IAppxManifestReader7), [pPoint.ref]) ..insert(Guid.parse(IID_IAppxManifestProperties), [pRect.ref]) @@ -68,16 +67,14 @@ void main() { final pickerGuid = Guid.parse(IID_IFileOpenPicker); final storageItemGuid = Guid.parse(IID_IStorageItem); map = IMap.fromMap({ - calendarGuid: Calendar(allocator: allocator), + calendarGuid: Calendar(), pickerGuid: 259, storageItemGuid: 'strVal', }); final calendarVal = map.lookup(calendarGuid); expect(calendarVal, isA()); - final calendar = - Calendar.fromRawPointer((calendarVal as IInspectable).ptr); - expect(calendar.runtimeClassName, + expect((calendarVal as IInspectable).runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup(pickerGuid), equals(259)); expect(map.lookup(storageItemGuid), equals('strVal')); @@ -97,9 +94,7 @@ void main() { final calendarVal = map.lookup(Guid.parse(IID_ICalendar)); expect(calendarVal, isA()); - final calendar = - Calendar.fromRawPointer((calendarVal as IInspectable).ptr); - expect(calendar.runtimeClassName, + expect((calendarVal as IInspectable).runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup(Guid.parse(IID_IStorageItem)), isTrue); @@ -168,8 +163,7 @@ void main() { map.lookup(Guid.parse(IID_IAppxManifestReader5)); expect(calendarListVal, isA>()); final calendarList = calendarListVal as List; - final calendar_ = Calendar.fromRawPointer(calendarList.first.ptr); - expect(calendar_.runtimeClassName, + expect(calendarList.first.runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup(Guid.parse(IID_IAppxManifestReader6)), @@ -291,6 +285,7 @@ void main() { }); tearDown(() { + map.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); @@ -318,7 +313,7 @@ void main() { map = IMap() ..insert('key1', null) - ..insert('key2', Calendar(allocator: allocator)) + ..insert('key2', Calendar()) ..insert('key3', true) ..insert('key4', DateTime(2022, 7, 11, 17, 30)) ..insert('key5', 0.5) @@ -335,7 +330,7 @@ void main() { ..insert('key15', [2.5, 0.99]) ..insert('key16', const [Duration(hours: 1), Duration(minutes: 60)]) ..insert('key17', [guid]) - ..insert('key18', [Calendar(allocator: allocator)]) + ..insert('key18', [Calendar()]) ..insert('key19', [2022, -2022]) ..insert('key20', [pPoint.ref]) ..insert('key21', [pRect.ref]) @@ -345,16 +340,14 @@ void main() { test('fromMap', () { map = IMap.fromMap({ - 'key1': Calendar(allocator: allocator), + 'key1': Calendar(), 'key2': 259, 'key3': 'strVal', }); final calendarVal = map.lookup('key1'); expect(calendarVal, isA()); - final calendar = - Calendar.fromRawPointer((calendarVal as IInspectable).ptr); - expect(calendar.runtimeClassName, + expect((calendarVal as IInspectable).runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup('key2'), equals(259)); expect(map.lookup('key3'), equals('strVal')); @@ -374,9 +367,7 @@ void main() { final calendarVal = map.lookup('key2'); expect(calendarVal, isA()); - final calendar = - Calendar.fromRawPointer((calendarVal as IInspectable).ptr); - expect(calendar.runtimeClassName, + expect((calendarVal as IInspectable).runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup('key3'), isTrue); @@ -442,8 +433,7 @@ void main() { final calendarListVal = map.lookup('key18'); expect(calendarListVal, isA>()); final calendarList = calendarListVal as List; - final calendar_ = Calendar.fromRawPointer(calendarList.first.ptr); - expect(calendar_.runtimeClassName, + expect(calendarList.first.runtimeClassName, equals('Windows.Globalization.Calendar')); expect(map.lookup('key19'), equals([2022, -2022])); @@ -551,6 +541,7 @@ void main() { }); tearDown(() { + map.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); @@ -564,7 +555,7 @@ void main() { winrtInitialize(); allocator = Arena(); final guid = Guid.parse(IID_ISpVoice); - final valueSet = ValueSet(allocator: allocator) + final valueSet = ValueSet() ..insert('key1', null) ..insert('key2', 'strVal'); final pPoint = allocator() @@ -579,7 +570,7 @@ void main() { ..ref.Height = 1500 ..ref.Width = 300; - map = ValueSet(allocator: allocator) + map = ValueSet() ..insert('key1', null) ..insert('key2', valueSet) ..insert('key3', true) @@ -619,8 +610,8 @@ void main() { final valueSetVal = map.lookup('key2'); expect(valueSetVal, isA()); - final valueSet = - ValueSet.fromRawPointer((valueSetVal as IInspectable).ptr); + final valueSet = ValueSet.fromRawPointer( + (valueSetVal as IInspectable).toInterface(IID_IMap_String_Object)); expect(valueSet.runtimeClassName, equals('Windows.Foundation.Collections.ValueSet')); expect(valueSet.size, equals(2)); @@ -779,7 +770,7 @@ void main() { }); test('first', () { - map = ValueSet(allocator: allocator) + map = ValueSet() ..insert('key1', 'icalendar') ..insert('key2', 259); @@ -794,6 +785,7 @@ void main() { }); tearDown(() { + map.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); @@ -1140,9 +1132,8 @@ void main() { setUp(() { winrtInitialize(); - allocator = Arena(); - picker = DevicePicker(allocator: allocator); + picker = DevicePicker(); pickerFilter = picker.filter; vector = pickerFilter.supportedDeviceClasses; }); @@ -1384,7 +1375,9 @@ void main() { }); tearDown(() { - free(pickerFilter.ptr); + vector.release(); + pickerFilter.release(); + picker.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); @@ -1397,9 +1390,8 @@ void main() { setUp(() { winrtInitialize(); - allocator = Arena(); - material = Printing3DMultiplePropertyMaterial(allocator: allocator); + material = Printing3DMultiplePropertyMaterial(); vector = material.materialIndices; }); @@ -1636,23 +1628,22 @@ void main() { }); tearDown(() { + vector.release(); + material.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); }); group('IVector', () { - late IFileOpenPicker picker; + late FileOpenPicker picker; late IVector vector; late Arena allocator; setUp(() { winrtInitialize(); - - final object = CreateObject( - 'Windows.Storage.Pickers.FileOpenPicker', IID_IFileOpenPicker); - picker = IFileOpenPicker.fromRawPointer(object); allocator = Arena(); + picker = FileOpenPicker(); vector = picker.fileTypeFilter; }); @@ -1885,7 +1876,8 @@ void main() { }); tearDown(() { - free(picker.ptr); + picker.release(); + vector.release(); allocator.releaseAll(reuse: true); winrtUninitialize(); }); @@ -1895,8 +1887,8 @@ void main() { late IVector vector; late Arena allocator; - IVector getServerUris(Pointer ptr, Allocator allocator) { - final retValuePtr = allocator(); + IVector getServerUris(Pointer ptr) { + final retValuePtr = calloc(); final hr = ptr.ref.vtable .elementAt(6) @@ -1921,7 +1913,7 @@ void main() { final object = CreateObject( 'Windows.Networking.Vpn.VpnPlugInProfile', IID_IVpnPlugInProfile); allocator = Arena(); - vector = getServerUris(object, allocator); + vector = getServerUris(object); }); test('getAt fails if the vector is empty', () { @@ -2072,24 +2064,22 @@ void main() { test('getMany returns 0 if the vector is empty', () { final pCOMObject = allocator(); - expect(vector.getMany(0, 1, pCOMObject), equals(0)); }); test('getMany returns elements starting from index 0', () { - final pCOMObject = allocator(2); + final pCOMObject = allocator(3); vector ..append(Uri.parse('https://dart.dev/overview')) ..append(Uri.parse('https://dart.dev/docs')) ..append(Uri.parse('https://flutter.dev/development')); expect(vector.getMany(0, 3, pCOMObject), equals(3)); - expect(winrt_uri.Uri.fromRawPointer(pCOMObject.elementAt(0)).toString(), - equals('https://dart.dev/overview')); - expect(winrt_uri.Uri.fromRawPointer(pCOMObject.elementAt(1)).toString(), - equals('https://dart.dev/docs')); - expect(winrt_uri.Uri.fromRawPointer(pCOMObject.elementAt(2)).toString(), - equals('https://flutter.dev/development')); + + final list = pCOMObject.toList(winrt_uri.Uri.fromRawPointer, length: 3); + expect(list.first.toString(), equals('https://dart.dev/overview')); + expect(list.elementAt(1).toString(), equals('https://dart.dev/docs')); + expect(list.last.toString(), equals('https://flutter.dev/development')); }); test('getMany returns elements starting from index 1', () { @@ -2100,9 +2090,14 @@ void main() { ..append(Uri.parse('https://dart.dev/docs')) ..append(Uri.parse('https://flutter.dev/development')); expect(vector.getMany(1, 2, pCOMObject), equals(2)); - expect(winrt_uri.Uri.fromRawPointer(pCOMObject.elementAt(0)).toString(), + + final firstElement = calloc() + ..ref = pCOMObject.elementAt(0).ref; + final secondElement = calloc() + ..ref = pCOMObject.elementAt(1).ref; + expect(winrt_uri.Uri.fromRawPointer(firstElement).toString(), equals('https://dart.dev/docs')); - expect(winrt_uri.Uri.fromRawPointer(pCOMObject.elementAt(1)).toString(), + expect(winrt_uri.Uri.fromRawPointer(secondElement).toString(), equals('https://flutter.dev/development')); }); @@ -2168,25 +2163,18 @@ void main() { late Arena allocator; late IVectorView vectorView; - IVectorView getLanguages( - Pointer ptr, Allocator allocator) { - final retValuePtr = allocator(); + IVectorView getLanguages(Pointer ptr) { + final retValuePtr = calloc(); final hr = ptr.ref.vtable - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function( - Pointer, - Pointer, - )>>>() - .value - .asFunction< - int Function( - Pointer, - Pointer, - )>()(ptr.ref.lpVtbl, retValuePtr); + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); if (FAILED(hr)) throw WindowsException(hr); @@ -2196,12 +2184,9 @@ void main() { setUp(() { winrtInitialize(); - allocator = Arena(); - final object = ActivateClass('Windows.Globalization.Calendar', - allocator: allocator); - allocator = Arena(); - vectorView = getLanguages(object, allocator); + final calendar = Calendar(); + vectorView = getLanguages(calendar.ptr); }); test('getAt throws exception if the index is out of bounds', () { @@ -2260,13 +2245,12 @@ void main() { }); }); - group('IVectorView', () { + group('IVectorView', () { late Arena allocator; - late IVectorView vectorView; + late IVectorView vectorView; - IVectorView getHostNames( - Pointer ptr, Allocator allocator) { - final retValuePtr = allocator(); + IVectorView getHostNames(Pointer ptr) { + final retValuePtr = calloc(); final hr = ptr.ref.vtable .elementAt(9) @@ -2281,19 +2265,18 @@ void main() { if (FAILED(hr)) throw WindowsException(hr); return IVectorView.fromRawPointer(retValuePtr, - creator: IHostName.fromRawPointer, + creator: HostName.fromRawPointer, iterableIid: IID_IIterable_HostName); } setUp(() { winrtInitialize(); - allocator = Arena(); final object = CreateActivationFactory( - 'Windows.Networking.Connectivity.NetworkInformation', - IID_INetworkInformationStatics, - allocator: allocator); - vectorView = getHostNames(object, allocator); + 'Windows.Networking.Connectivity.NetworkInformation', + IID_INetworkInformationStatics, + ); + vectorView = getHostNames(object); }); test('getAt throws exception if the index is out of bounds', () { diff --git a/test/winrt_ireference_test.dart b/test/winrt_ireference_test.dart index 365eeed550..2f93e69fe9 100644 --- a/test/winrt_ireference_test.dart +++ b/test/winrt_ireference_test.dart @@ -20,6 +20,9 @@ void main() { referenceIid: IID_IReference_Boolean); expect(ireference.value, isNotNull); expect(ireference.value, isTrue); + + ireference.release(); + pv.release(); }); test('IReference', () { @@ -31,6 +34,9 @@ void main() { expect(ireference.value, isNotNull); expect(ireference.value!.millisecondsSinceEpoch, dateTime.millisecondsSinceEpoch); + + ireference.release(); + pv.release(); }); test('IReference (Double)', () { @@ -40,6 +46,9 @@ void main() { referenceIid: IID_IReference_Double); expect(ireference.value, isNotNull); expect(ireference.value, equals(3.0)); + + ireference.release(); + pv.release(); }); test('IReference (Float)', () { @@ -49,6 +58,9 @@ void main() { referenceIid: IID_IReference_Float); expect(ireference.value, isNotNull); expect(ireference.value, equals(3.0)); + + ireference.release(); + pv.release(); }); test('IReference', () { @@ -59,6 +71,9 @@ void main() { referenceIid: IID_IReference_TimeSpan); expect(ireference.value, isNotNull); expect(ireference.value, equals(duration)); + + ireference.release(); + pv.release(); }); test('IReference', () { @@ -68,6 +83,9 @@ void main() { referenceIid: IID_IReference_Guid); expect(ireference.value, isNotNull); expect(ireference.value!.toString(), equals(IID_ICalendar)); + + ireference.release(); + pv.release(); }); test('IReference (Int16)', () { @@ -77,6 +95,9 @@ void main() { referenceIid: IID_IReference_Int16); expect(ireference.value, isNotNull); expect(ireference.value, equals(16)); + + ireference.release(); + pv.release(); }); test('IReference (Int32)', () { @@ -86,6 +107,9 @@ void main() { referenceIid: IID_IReference_Int32); expect(ireference.value, isNotNull); expect(ireference.value, equals(32)); + + ireference.release(); + pv.release(); }); test('IReference (Int64)', () { @@ -95,6 +119,9 @@ void main() { referenceIid: IID_IReference_Int64); expect(ireference.value, isNotNull); expect(ireference.value, equals(64)); + + ireference.release(); + pv.release(); }); test('IReference (Uint8)', () { @@ -104,6 +131,9 @@ void main() { referenceIid: IID_IReference_Uint8); expect(ireference.value, isNotNull); expect(ireference.value, equals(8)); + + ireference.release(); + pv.release(); }); test('IReference (Uint32)', () { @@ -113,6 +143,9 @@ void main() { referenceIid: IID_IReference_Uint32); expect(ireference.value, isNotNull); expect(ireference.value, equals(32)); + + ireference.release(); + pv.release(); }); test('IReference (Uint64)', () { @@ -122,28 +155,35 @@ void main() { referenceIid: IID_IReference_Uint64); expect(ireference.value, isNotNull); expect(ireference.value, equals(64)); + + ireference.release(); + pv.release(); }); test('IReference', () { - final point = calloc() + final pointPtr = calloc() ..ref.X = 50 ..ref.Y = 100; - final pv = PropertyValue.createPoint(point.ref); + final pv = PropertyValue.createPoint(pointPtr.ref); final ireference = IReference.fromRawPointer( pv.toInterface(IID_IReference_Point), referenceIid: IID_IReference_Point); expect(ireference.value, isNotNull); expect(ireference.value!.X, equals(50)); expect(ireference.value!.Y, equals(100)); + + ireference.release(); + pv.release(); + free(pointPtr); }); test('IReference', () { - final rect = calloc() + final rectPtr = calloc() ..ref.Height = 200 ..ref.Width = 100 ..ref.X = 50 ..ref.Y = 100; - final pv = PropertyValue.createRect(rect.ref); + final pv = PropertyValue.createRect(rectPtr.ref); final ireference = IReference.fromRawPointer( pv.toInterface(IID_IReference_Rect), referenceIid: IID_IReference_Rect); @@ -152,19 +192,27 @@ void main() { expect(ireference.value!.Width, equals(100)); expect(ireference.value!.X, equals(50)); expect(ireference.value!.Y, equals(100)); + + ireference.release(); + pv.release(); + free(rectPtr); }); test('IReference', () { - final size = calloc() + final sizePtr = calloc() ..ref.Height = 200 ..ref.Width = 100; - final pv = PropertyValue.createSize(size.ref); + final pv = PropertyValue.createSize(sizePtr.ref); final ireference = IReference.fromRawPointer( pv.toInterface(IID_IReference_Size), referenceIid: IID_IReference_Size); expect(ireference.value, isNotNull); expect(ireference.value!.Height, equals(200)); expect(ireference.value!.Width, equals(100)); + + ireference.release(); + pv.release(); + free(sizePtr); }); tearDown(winrtUninitialize); diff --git a/test/winrt_phonenumberformatter_test.dart b/test/winrt_phonenumberformatter_test.dart index 30959c1349..0af0cb9871 100644 --- a/test/winrt_phonenumberformatter_test.dart +++ b/test/winrt_phonenumberformatter_test.dart @@ -32,6 +32,8 @@ void main() { PhoneNumberFormatter.tryCreate('US', usFormatter); final phone = usFormatter.formatString('4255550123'); expect(phone, equals('(425) 555-0123')); + + usFormatter.release(); }); test('Create a formatter for a different region code', () { @@ -44,6 +46,8 @@ void main() { expect(london, equals('020 7946 0123')); final reading = ukFormatter.formatString('01184960987'); expect(reading, equals('0118 496 0987')); + + ukFormatter.release(); }); test('Country codes for regions', () { @@ -68,7 +72,7 @@ void main() { }); tearDown(() { - free(formatter.ptr); + formatter.release(); winrtUninitialize(); }); } diff --git a/test/winrt_propertyvalue_test.dart b/test/winrt_propertyvalue_test.dart index 8f35165d20..6ad81e902d 100644 --- a/test/winrt_propertyvalue_test.dart +++ b/test/winrt_propertyvalue_test.dart @@ -4,6 +4,7 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:test/test.dart'; +import 'package:win32/src/winrt/internal/comobject_pointer.dart'; import 'package:win32/winrt.dart'; // Test the WinRT PropertyValue object to make sure overrides, properties and @@ -17,6 +18,8 @@ void main() { final pv = PropertyValue.createUInt8(30); expect(pv.type, equals(PropertyType.uInt8)); expect(pv.getUInt8(), equals(30)); + + pv.release(); }); test('UInt8Array', () { @@ -37,12 +40,16 @@ void main() { expect(newArray.value[2], equals(30)); expect(newArray.value[3], equals(40)); expect(newArray.value[4], equals(50)); + + pv.release(); }); test('UInt16', () { final pv = PropertyValue.createUInt16(65534); expect(pv.type, equals(PropertyType.uInt16)); expect(pv.getUInt16(), equals(65534)); + + pv.release(); }); test('UInt16Array', () { @@ -63,12 +70,16 @@ void main() { expect(newArray.value[2], equals(300)); expect(newArray.value[3], equals(400)); expect(newArray.value[4], equals(500)); + + pv.release(); }); test('Guid', () { final pv = PropertyValue.createGuid(Guid.parse(IID_ICalendar)); expect(pv.type, equals(PropertyType.guid)); expect(pv.getGuid().toString(), equals(IID_ICalendar)); + + pv.release(); }); test('GuidArray', () { @@ -87,6 +98,8 @@ void main() { expect(newArray.value[0].toString(), equals(IID_ICalendar)); expect(newArray.value[1].toString(), equals(IID_IFileOpenPicker)); expect(newArray.value[2].toString(), equals(IID_IStorageItem)); + + pv.release(); }); test('Inspectable', () { @@ -94,12 +107,16 @@ void main() { final pv = PropertyValue.createInspectable(calendar.ptr); expect(IInspectable(pv).runtimeClassName, equals('Windows.Globalization.Calendar')); + + calendar.release(); }); test('InspectableArray', () { + final calendar = Calendar(); + final formatter = PhoneNumberFormatter(); final array = calloc(2); - array[0] = Calendar().ptr.ref; - array[1] = PhoneNumberFormatter().ptr.ref; + array[0] = calendar.ptr.ref; + array[1] = formatter.ptr.ref; final pv = PropertyValue.createInspectableArray(2, array); expect(pv.type, equals(PropertyType.inspectableArray)); @@ -108,12 +125,21 @@ void main() { pv.getInspectableArray(arraySize, newArray); expect(arraySize.value, equals(2)); - expect(IInspectable(newArray.value.elementAt(0)).runtimeClassName, + final list = newArray.value.toList(IInspectable.new, length: 2); + final firstElement = list.first; + final lastElement = list.last; + expect(firstElement.runtimeClassName, equals('Windows.Globalization.Calendar')); expect( - IInspectable(newArray.value.elementAt(1)).runtimeClassName, + lastElement.runtimeClassName, equals( 'Windows.Globalization.PhoneNumberFormatting.PhoneNumberFormatter')); + + lastElement.release(); + firstElement.release(); + free(newArray); + pv.release(); + free(array); }); tearDown(winrtUninitialize); diff --git a/test/winrt_test.dart b/test/winrt_test.dart index 5813cc5186..a9d2ad9d26 100644 --- a/test/winrt_test.dart +++ b/test/winrt_test.dart @@ -1,6 +1,5 @@ @TestOn('windows') -import 'package:ffi/ffi.dart'; import 'package:test/test.dart'; import 'package:win32/winrt.dart'; @@ -44,9 +43,9 @@ void main() { winrtInitialize(); final calendar = Calendar(); - expect(calendar.year, greaterThanOrEqualTo(2020)); - free(calendar.ptr); + + calendar.release(); winrtUninitialize(); }); @@ -61,10 +60,9 @@ void main() { ]; final calendar = Calendar(); - expect(calendar.iids, equals(iids)); - free(calendar.ptr); + calendar.release(); winrtUninitialize(); }); @@ -73,21 +71,20 @@ void main() { const calendarClassName = 'Windows.Globalization.Calendar'; - using((Arena arena) { - final calendar = Calendar(allocator: arena); - expect(calendar.runtimeClassName, equals(calendarClassName)); - }); + final calendar = Calendar(); + expect(calendar.runtimeClassName, equals(calendarClassName)); + calendar.release(); winrtUninitialize(); }); test('WinRT getTrustLevel test of base trust class', () { winrtInitialize(); - using((Arena arena) { - final calendar = Calendar(allocator: arena); - expect(calendar.trustLevel, equals(TrustLevel.baseTrust)); - }); + final calendar = Calendar(); + expect(calendar.trustLevel, equals(TrustLevel.baseTrust)); + + calendar.release(); winrtUninitialize(); }); @@ -98,10 +95,9 @@ void main() { final object = CreateObject(className, IID_IInspectable); final inspectableObject = IInspectable(object); - expect(inspectableObject.trustLevel, equals(TrustLevel.partialTrust)); - free(object); + inspectableObject.release(); winrtUninitialize(); }); } diff --git a/test/winrt_uri_test.dart b/test/winrt_uri_test.dart index 6becf6865f..892bc1825c 100644 --- a/test/winrt_uri_test.dart +++ b/test/winrt_uri_test.dart @@ -30,14 +30,17 @@ void main() { expect(winrtUri.path, equals('/path/to/file.html')); expect(winrtUri.extension, equals('.html')); expect(winrtUri.query, equals('?q1=v1&q2=v2')); - expect(winrtUri.queryParsed.size, equals(2)); - final queryParameters = winrtUri.queryParsed.toList(); + final queryParsed = winrtUri.queryParsed; + expect(queryParsed.size, equals(2)); + final queryParameters = queryParsed.toList(); expect(queryParameters.length, equals(2)); expect(queryParameters.first.name, equals('q1')); expect(queryParameters.first.value, equals('v1')); expect(queryParameters.last.name, equals('q2')); expect(queryParameters.last.value, equals('v2')); expect(winrtUri.fragment, equals('#fragment')); + + winrtUri.release(); }); tearDown(winrtUninitialize); diff --git a/tool/generator/test/goldens/icalendar.golden b/tool/generator/test/goldens/icalendar.golden index 4a0e81b1a7..6359509cb2 100644 --- a/tool/generator/test/goldens/icalendar.golden +++ b/tool/generator/test/goldens/icalendar.golden @@ -80,24 +80,27 @@ class ICalendar extends IInspectable { List get languages { final retValuePtr = calloc(); - try { - final hr = ptr.ref.vtable - .elementAt(9) - .cast< - Pointer< - NativeFunction< - HRESULT Function(Pointer, Pointer)>>>() - .value - .asFunction)>()( - ptr.ref.lpVtbl, retValuePtr); + final hr = ptr.ref.vtable + .elementAt(9) + .cast< + Pointer< + NativeFunction< + HRESULT Function(Pointer, Pointer)>>>() + .value + .asFunction)>()( + ptr.ref.lpVtbl, retValuePtr); - if (FAILED(hr)) throw WindowsException(hr); - return IVectorView.fromRawPointer(retValuePtr, - iterableIid: '{e2fcc7c1-3bfc-5a0b-b2b0-72e769d1cb7e}') - .toList(); - } finally { + if (FAILED(hr)) { free(retValuePtr); + throw WindowsException(hr); } + + final vectorView = IVectorView.fromRawPointer(retValuePtr, + iterableIid: '{e2fcc7c1-3bfc-5a0b-b2b0-72e769d1cb7e}'); + final list = vectorView.toList(); + vectorView.release(); + + return list; } String get numeralSystem { @@ -166,6 +169,7 @@ class ICalendar extends IInspectable { void changeCalendarSystem(String value) { final valueHstring = convertToHString(value); + final hr = ptr.ref.vtable .elementAt(13) .cast< @@ -175,6 +179,7 @@ class ICalendar extends IInspectable { int Function(Pointer, int value)>()(ptr.ref.lpVtbl, valueHstring); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(valueHstring); } @@ -204,6 +209,7 @@ class ICalendar extends IInspectable { void changeClock(String value) { final valueHstring = convertToHString(value); + final hr = ptr.ref.vtable .elementAt(15) .cast< @@ -213,6 +219,7 @@ class ICalendar extends IInspectable { int Function(Pointer, int value)>()(ptr.ref.lpVtbl, valueHstring); if (FAILED(hr)) throw WindowsException(hr); + WindowsDeleteString(valueHstring); } @@ -242,6 +249,7 @@ class ICalendar extends IInspectable { void setDateTime(DateTime value) { final valueDateTime = value.difference(DateTime.utc(1601, 01, 01)).inMicroseconds * 10; + final hr = ptr.ref.vtable .elementAt(17) .cast< diff --git a/tool/generator/test/winrt_projection_test.dart b/tool/generator/test/winrt_projection_test.dart index de519f467a..66e0cff586 100644 --- a/tool/generator/test/winrt_projection_test.dart +++ b/tool/generator/test/winrt_projection_test.dart @@ -396,10 +396,10 @@ void main() { expect(expirationTimeProjection.returnType.dartType, equals('void')); expect(expirationTimeProjection.toString().trimLeft(), startsWith('set expirationTime(DateTime? value)')); - expect( - expirationTimeProjection.toString(), - contains( - 'final referencePtr = boxValue(value, convertToIReference: true);')); + expect(expirationTimeProjection.toString(), + contains('''final referencePtr = value == null + ? calloc() + : boxValue(value, convertToIReference: true);''')); }); test('WinRT set property successfully projects nullable enum parameter', () { @@ -417,10 +417,10 @@ void main() { expect(flagsProjection.returnType.dartType, equals('void')); expect(flagsProjection.toString().trimLeft(), startsWith('set flags(BluetoothLEAdvertisementFlags? value)')); - expect( - flagsProjection.toString(), - contains( - 'final referencePtr = boxValue(value?.value, convertToIReference: true, nativeType: Uint32);')); + expect(flagsProjection.toString(), + contains('''final referencePtr = value == null + ? calloc() + : boxValue(value?.value, convertToIReference: true, nativeType: Uint32);''')); }); test('WinRT method projects DateTime parameter correctly', () { @@ -489,7 +489,7 @@ void main() { expect( projection.defaultConstructor, equalsIgnoringWhitespace( - 'FileOpenPicker({Allocator allocator = calloc}) : super(ActivateClass(_className, allocator: allocator));')); + 'FileOpenPicker() : super(ActivateClass(_className));')); }); test('WinRT class does not project a default constructor', () { @@ -664,7 +664,9 @@ void main() { contains( 'final winrtUri = winrt_uri.Uri.fromRawPointer(retValuePtr);')); expect(fallbackUriProjection.toString().trimLeft(), - contains('return Uri.parse(winrtUri.toString());')); + contains('final uriAsString = winrtUri.toString();')); + expect(fallbackUriProjection.toString().trimLeft(), + contains('return Uri.parse(uriAsString);')); }); test('WinRT set property successfully projects Uri', () { @@ -699,7 +701,7 @@ void main() { launchUriAsyncProjection.parameters.first as WinRTParameterProjection; expect(uriParameter.preamble, equals('final uriUri = winrt_uri.Uri.createUri(uri.toString());')); - expect(uriParameter.postamble, equals('free(uriUri.ptr);')); + expect(uriParameter.postamble, equals('uriUri.release();')); expect(uriParameter.localIdentifier, equals('uriUri.ptr.cast>().value')); expect(uriParameter.type.methodParamType, equals('Uri')); From a804552a4033d7040daf8d47259fac9c5bce0e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 23 Dec 2022 11:54:47 +0300 Subject: [PATCH 16/17] Address review comments --- lib/src/com/iunknown.dart | 19 +++++++++---------- lib/src/winrt_helpers.dart | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/src/com/iunknown.dart b/lib/src/com/iunknown.dart index f85225f93a..b43856d6aa 100644 --- a/lib/src/com/iunknown.dart +++ b/lib/src/com/iunknown.dart @@ -12,11 +12,6 @@ import '../guid.dart'; import '../macros.dart'; import '../utils.dart'; -typedef WinCoTaskMemFreeNative = Void Function(Pointer pv); -final ole32Lib = DynamicLibrary.open('ole32.dll'); -final winCoTaskMemFree = - ole32Lib.lookup>('CoTaskMemFree'); - /// @nodoc const IID_IUnknown = '{00000000-0000-0000-c000-000000000046}'; @@ -34,10 +29,14 @@ class IUnknown implements Finalizable { Pointer ptr; IUnknown(this.ptr) { - _finalizer.attach(this, ptr.cast(), detach: this, externalSize: 8); + _finalizer.attach(this, ptr.cast(), + detach: this, externalSize: sizeOf()); } - static final _finalizer = NativeFinalizer(winCoTaskMemFree.cast()); + static final _ole32Lib = DynamicLibrary.open('ole32.dll'); + static final _winCoTaskMemFree = _ole32Lib + .lookup>('CoTaskMemFree'); + static final _finalizer = NativeFinalizer(_winCoTaskMemFree.cast()); factory IUnknown.from(IUnknown interface) => IUnknown(interface.toInterface(IID_IUnknown)); @@ -83,14 +82,14 @@ class IUnknown implements Finalizable { /// a COM QueryInterface to return a reference to that interface. This method /// reduces the boilerplate associated with calling `queryInterface` manually. Pointer toInterface(String iid) { - final nativeGuidPtr = convertToIID(iid); + final pIID = convertToIID(iid); final objectPtr = calloc(); try { - final hr = queryInterface(nativeGuidPtr, objectPtr.cast()); + final hr = queryInterface(pIID, objectPtr.cast()); if (FAILED(hr)) throw WindowsException(hr); return objectPtr; } finally { - free(nativeGuidPtr); + free(pIID); } } } diff --git a/lib/src/winrt_helpers.dart b/lib/src/winrt_helpers.dart index 43d578aa4e..45c0fac20e 100644 --- a/lib/src/winrt_helpers.dart +++ b/lib/src/winrt_helpers.dart @@ -102,17 +102,17 @@ Pointer CreateActivationFactory(String className, String iid, {Allocator allocator = calloc}) { // Create a HSTRING representing the object final hClassName = convertToHString(className); - final nativeGuidPtr = GUIDFromString(iid); + final pIID = GUIDFromString(iid); final activationFactoryPtr = allocator(); try { - final hr = RoGetActivationFactory( - hClassName, nativeGuidPtr, activationFactoryPtr.cast()); + final hr = + RoGetActivationFactory(hClassName, pIID, activationFactoryPtr.cast()); if (FAILED(hr)) throw WindowsException(hr); // Return a pointer to the relevant class return activationFactoryPtr; } finally { - free(nativeGuidPtr); + free(pIID); WindowsDeleteString(hClassName); } } From f40f3331034235ee42ea24da9481b87d81cf7399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Durmu=C5=9F?= Date: Fri, 23 Dec 2022 11:56:13 +0300 Subject: [PATCH 17/17] Call release on INetwork --- example/network.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/example/network.dart b/example/network.dart index a768a8efe6..bcd1684f6e 100644 --- a/example/network.dart +++ b/example/network.dart @@ -62,6 +62,7 @@ void main() { '$networkName: ${isNetworkConnected ? 'connected' : 'disconnected'}'); } + network.release(); netPtr = calloc(); hr = enumerator.next(1, netPtr.cast(), elements); }