diff --git a/src/WinRT.Interop.Generator/Extensions/WindowsRuntimeExtensions.cs b/src/WinRT.Interop.Generator/Extensions/WindowsRuntimeExtensions.cs index 43cac0eb8..da9d56ac4 100644 --- a/src/WinRT.Interop.Generator/Extensions/WindowsRuntimeExtensions.cs +++ b/src/WinRT.Interop.Generator/Extensions/WindowsRuntimeExtensions.cs @@ -183,7 +183,8 @@ public bool IsManuallyProjectedWindowsRuntimeNonGenericStructOrClassType(Interop SignatureComparer.IgnoreVersion.Equals(type, interopReferences.Point) || SignatureComparer.IgnoreVersion.Equals(type, interopReferences.Rect) || SignatureComparer.IgnoreVersion.Equals(type, interopReferences.Size) || - SignatureComparer.IgnoreVersion.Equals(type, interopReferences.EventRegistrationToken); + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.EventRegistrationToken) || + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.InputStreamOptions); } /// @@ -248,7 +249,11 @@ public bool IsManuallyProjectedWindowsRuntimeNonGenericInterfaceType(InteropRefe SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IAsyncAction) || SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IAsyncInfo) || SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IVectorChangedEventArgs) || - SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IStringable); + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IStringable) || + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IBuffer) || + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IInputStream) || + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IOutputStream) || + SignatureComparer.IgnoreVersion.Equals(type, interopReferences.IRandomAccessStream); } /// diff --git a/src/WinRT.Interop.Generator/References/InteropReferences.cs b/src/WinRT.Interop.Generator/References/InteropReferences.cs index 17c82b425..e0b1f24c8 100644 --- a/src/WinRT.Interop.Generator/References/InteropReferences.cs +++ b/src/WinRT.Interop.Generator/References/InteropReferences.cs @@ -1489,6 +1489,31 @@ public InteropReferences( /// public TypeReference AsyncOperationWithProgressCompletedHandler2 => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Foundation"u8, "AsyncOperationWithProgressCompletedHandler`2"u8); + /// + /// Gets the for Windows.Storage.Streams.IBuffer. + /// + public TypeReference IBuffer => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IBuffer"u8); + + /// + /// Gets the for Windows.Storage.Streams.IInputStream. + /// + public TypeReference IInputStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IInputStream"u8); + + /// + /// Gets the for Windows.Storage.Streams.IOutputStream. + /// + public TypeReference IOutputStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IOutputStream"u8); + + /// + /// Gets the for Windows.Storage.Streams.IRandomAccessStream. + /// + public TypeReference IRandomAccessStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IRandomAccessStream"u8); + + /// + /// Gets the for Windows.Storage.Streams.InputStreamOptions. + /// + public TypeReference InputStreamOptions => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "InputStreamOptions"u8); + /// /// Gets the for . /// diff --git a/src/WinRT.Interop.Generator/References/WellKnownInterfaceIIDs.cs b/src/WinRT.Interop.Generator/References/WellKnownInterfaceIIDs.cs index c65320373..ec98eb000 100644 --- a/src/WinRT.Interop.Generator/References/WellKnownInterfaceIIDs.cs +++ b/src/WinRT.Interop.Generator/References/WellKnownInterfaceIIDs.cs @@ -88,6 +88,14 @@ _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.I => "Windows_Foundation_IAsyncAction", _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IVectorChangedEventArgs) => "Windows_Foundation_Collections_IVectorChangedEventArgs", + _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IBuffer) + => "Windows_Storage_Streams_IBuffer", + _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IInputStream) + => "Windows_Storage_Streams_IInputStream", + _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IOutputStream) + => "Windows_Storage_Streams_IOutputStream", + _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IRandomAccessStream) + => "Windows_Storage_Streams_IRandomAccessStream", // XAML types _ when SignatureComparer.IgnoreVersion.Equals(interfaceType, interopReferences.IEnumerable) && useWindowsUIXamlProjections diff --git a/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IBuffer.cs b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IBuffer.cs new file mode 100644 index 000000000..fb1c0d584 --- /dev/null +++ b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IBuffer.cs @@ -0,0 +1,259 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Storage.Streams; +using WindowsRuntime; +using WindowsRuntime.InteropServices; +using WindowsRuntime.InteropServices.Marshalling; +using static System.Runtime.InteropServices.ComWrappers; + +#pragma warning disable IDE0008, IDE1006 + +#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code +[assembly: TypeMap( + value: "Windows.Storage.Streams.IBuffer", + target: typeof(IBuffer), + trimTarget: typeof(IBuffer))] +#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code + +[assembly: TypeMapAssociation( + source: typeof(IBuffer), + proxy: typeof(ABI.Windows.Storage.Streams.IBufferInterfaceImpl))] + +namespace ABI.Windows.Storage.Streams; + +/// +/// Marshaller for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IBufferMarshaller +{ + /// + public static WindowsRuntimeObjectReferenceValue ConvertToUnmanaged(IBuffer? value) + { + return WindowsRuntimeInterfaceMarshaller.ConvertToUnmanaged(value, in WellKnownWindowsInterfaceIIDs.IID_IBuffer); + } + + /// + public static IBuffer? ConvertToManaged(void* value) + { + return (IBuffer?)WindowsRuntimeObjectMarshaller.ConvertToManaged(value); + } +} + +/// +/// Interop methods for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IBufferMethods +{ + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint Capacity(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + uint result; + + HRESULT hresult = ((IBufferVftbl*)*(void***)thisPtr)->get_Capacity(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static uint Length(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + uint result; + + HRESULT hresult = ((IBufferVftbl*)*(void***)thisPtr)->get_Length(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Length(WindowsRuntimeObjectReference thisReference, uint value) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + + HRESULT hresult = ((IBufferVftbl*)*(void***)thisPtr)->set_Length(thisPtr, value); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + } +} + +/// +/// Binding type for . +/// +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct IBufferVftbl +{ + public delegate* unmanaged[MemberFunction] QueryInterface; + public delegate* unmanaged[MemberFunction] AddRef; + public delegate* unmanaged[MemberFunction] Release; + public delegate* unmanaged[MemberFunction] GetIids; + public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + public delegate* unmanaged[MemberFunction] GetTrustLevel; + public delegate* unmanaged[MemberFunction] get_Capacity; + public delegate* unmanaged[MemberFunction] get_Length; + public delegate* unmanaged[MemberFunction] set_Length; +} + +/// +/// The implementation. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IBufferImpl +{ + /// + /// The value for the managed implementation. + /// + [FixedAddressValueType] + private static readonly IBufferVftbl Vftbl; + + /// + /// Initializes . + /// + static IBufferImpl() + { + *(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable; + + Vftbl.get_Capacity = &get_Capacity; + Vftbl.get_Length = &get_Length; + Vftbl.set_Length = &set_Length; + } + + /// + /// Gets a pointer to the managed implementation. + /// + public static nint Vtable + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => (nint)Unsafe.AsPointer(in Vftbl); + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_Capacity(void* thisPtr, uint* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.Capacity; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_Length(void* thisPtr, uint* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.Length; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT set_Length(void* thisPtr, uint value) + { + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + thisObject.Length = value; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } +} + +/// +/// The implementation for . +/// +[DynamicInterfaceCastableImplementation] +[Guid("905A0FE0-BC53-11DF-8C49-001E4FC686DA")] +file interface IBufferInterfaceImpl : IBuffer +{ + /// + uint IBuffer.Capacity + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); + + return IBufferMethods.Capacity(thisReference); + } + } + + /// + uint IBuffer.Length + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); + + return IBufferMethods.Length(thisReference); + } + set + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); + + IBufferMethods.Length(thisReference, value); + } + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IInputStream.cs b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IInputStream.cs new file mode 100644 index 000000000..9ac20015b --- /dev/null +++ b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IInputStream.cs @@ -0,0 +1,197 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Storage.Streams; +using WindowsRuntime; +using WindowsRuntime.InteropServices; +using WindowsRuntime.InteropServices.Marshalling; +using static System.Runtime.InteropServices.ComWrappers; + +#pragma warning disable CA2256, IDE0008, IDE1006 + +#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code +[assembly: TypeMap( + value: "Windows.Storage.Streams.IInputStream", + target: typeof(IInputStream), + trimTarget: typeof(IInputStream))] +#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code + +[assembly: TypeMapAssociation( + source: typeof(IInputStream), + proxy: typeof(ABI.Windows.Storage.Streams.IInputStreamInterfaceImpl))] + +namespace ABI.Windows.Storage.Streams; + +/// +/// Marshaller for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IInputStreamMarshaller +{ + /// + public static WindowsRuntimeObjectReferenceValue ConvertToUnmanaged(IInputStream? value) + { + return WindowsRuntimeInterfaceMarshaller.ConvertToUnmanaged(value, in WellKnownWindowsInterfaceIIDs.IID_IInputStream); + } + + /// + public static IInputStream? ConvertToManaged(void* value) + { + return (IInputStream?)WindowsRuntimeObjectMarshaller.ConvertToManaged(value); + } +} + +/// +/// Interop methods for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IInputStreamMethods +{ + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IAsyncOperationWithProgress ReadAsync( + WindowsRuntimeObjectReference thisReference, + IBuffer buffer, + uint count, + InputStreamOptions options) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + using WindowsRuntimeObjectReferenceValue bufferValue = IBufferMarshaller.ConvertToUnmanaged(buffer); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IInputStreamVftbl*)*(void***)thisPtr)->ReadAsync( + thisPtr, + bufferValue.GetThisPtrUnsafe(), + count, + options, + &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern IAsyncOperationWithProgress? ConvertToManaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperationWithProgress'2<<#CsWinRT>Windows.Storage.Streams.IBuffer|uint>Marshaller, WinRT.Interop")] object? _, + void* value); + + return ConvertToManaged(null, result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } +} + +/// +/// Binding type for . +/// +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct IInputStreamVftbl +{ + public delegate* unmanaged[MemberFunction] QueryInterface; + public delegate* unmanaged[MemberFunction] AddRef; + public delegate* unmanaged[MemberFunction] Release; + public delegate* unmanaged[MemberFunction] GetIids; + public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + public delegate* unmanaged[MemberFunction] GetTrustLevel; + public delegate* unmanaged[MemberFunction] ReadAsync; +} + +/// +/// The implementation. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IInputStreamImpl +{ + /// + /// The value for the managed implementation. + /// + [FixedAddressValueType] + private static readonly IInputStreamVftbl Vftbl; + + /// + /// Initializes . + /// + static IInputStreamImpl() + { + *(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable; + + Vftbl.ReadAsync = &ReadAsync; + } + + /// + /// Gets a pointer to the managed implementation. + /// + public static nint Vtable + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => (nint)Unsafe.AsPointer(in Vftbl); + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT ReadAsync(void* thisPtr, void* buffer, uint count, InputStreamOptions options, void** result) + { + if (buffer is null || result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IAsyncOperationWithProgress operation = thisObject.ReadAsync( + buffer: IBufferMarshaller.ConvertToManaged(buffer)!, + count: count, + options: options); + + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern WindowsRuntimeObjectReferenceValue ConvertToUnmanaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperationWithProgress'2<<#CsWinRT>Windows.Storage.Streams.IBuffer|uint>Marshaller, WinRT.Interop")] object? _, + IAsyncOperationWithProgress? value); + + *result = ConvertToUnmanaged(null, operation).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } +} + +/// +/// The implementation for . +/// +[DynamicInterfaceCastableImplementation] +[Guid("905A0FE2-BC53-11DF-8C49-001E4FC686DA")] +file interface IInputStreamInterfaceImpl : IInputStream +{ + /// + IAsyncOperationWithProgress IInputStream.ReadAsync(IBuffer buffer, uint count, InputStreamOptions options) + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IInputStream).TypeHandle); + + return IInputStreamMethods.ReadAsync(thisReference, buffer, count, options); + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IOutputStream.cs b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IOutputStream.cs new file mode 100644 index 000000000..cac59c774 --- /dev/null +++ b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IOutputStream.cs @@ -0,0 +1,256 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Storage.Streams; +using WindowsRuntime; +using WindowsRuntime.InteropServices; +using WindowsRuntime.InteropServices.Marshalling; +using static System.Runtime.InteropServices.ComWrappers; + +#pragma warning disable CA2256, IDE0008, IDE1006 + +#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code +[assembly: TypeMap( + value: "Windows.Storage.Streams.IOutputStream", + target: typeof(IOutputStream), + trimTarget: typeof(IOutputStream))] +#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code + +[assembly: TypeMapAssociation( + source: typeof(IOutputStream), + proxy: typeof(ABI.Windows.Storage.Streams.IOutputStreamInterfaceImpl))] + +namespace ABI.Windows.Storage.Streams; + +/// +/// Marshaller for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IOutputStreamMarshaller +{ + /// + public static WindowsRuntimeObjectReferenceValue ConvertToUnmanaged(IOutputStream? value) + { + return WindowsRuntimeInterfaceMarshaller.ConvertToUnmanaged(value, in WellKnownWindowsInterfaceIIDs.IID_IOutputStream); + } + + /// + public static IOutputStream? ConvertToManaged(void* value) + { + return (IOutputStream?)WindowsRuntimeObjectMarshaller.ConvertToManaged(value); + } +} + +/// +/// Interop methods for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IOutputStreamMethods +{ + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IAsyncOperationWithProgress WriteAsync(WindowsRuntimeObjectReference thisReference, IBuffer buffer) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + using WindowsRuntimeObjectReferenceValue bufferValue = IBufferMarshaller.ConvertToUnmanaged(buffer); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IOutputStreamVftbl*)*(void***)thisPtr)->WriteAsync( + thisPtr, + bufferValue.GetThisPtrUnsafe(), + &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern IAsyncOperationWithProgress? ConvertToManaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperationWithProgress'2Marshaller, WinRT.Interop")] object? _, + void* value); + + return ConvertToManaged(null, result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IAsyncOperation FlushAsync(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IOutputStreamVftbl*)*(void***)thisPtr)->FlushAsync(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern IAsyncOperation? ConvertToManaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperation'1Marshaller, WinRT.Interop")] object? _, + void* value); + + return ConvertToManaged(null, result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } +} + +/// +/// Binding type for . +/// +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct IOutputStreamVftbl +{ + public delegate* unmanaged[MemberFunction] QueryInterface; + public delegate* unmanaged[MemberFunction] AddRef; + public delegate* unmanaged[MemberFunction] Release; + public delegate* unmanaged[MemberFunction] GetIids; + public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + public delegate* unmanaged[MemberFunction] GetTrustLevel; + public delegate* unmanaged[MemberFunction] WriteAsync; + public delegate* unmanaged[MemberFunction] FlushAsync; +} + +/// +/// The implementation. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IOutputStreamImpl +{ + /// + /// The value for the managed implementation. + /// + [FixedAddressValueType] + private static readonly IOutputStreamVftbl Vftbl; + + /// + /// Initializes . + /// + static IOutputStreamImpl() + { + *(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable; + + Vftbl.WriteAsync = &WriteAsync; + Vftbl.FlushAsync = &FlushAsync; + } + + /// + /// Gets a pointer to the managed implementation. + /// + public static nint Vtable + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => (nint)Unsafe.AsPointer(in Vftbl); + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT WriteAsync(void* thisPtr, void* buffer, void** result) + { + if (buffer is null || result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IAsyncOperationWithProgress operation = thisObject.WriteAsync(IBufferMarshaller.ConvertToManaged(buffer)!); + + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern WindowsRuntimeObjectReferenceValue ConvertToUnmanaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperationWithProgress'2Marshaller, WinRT.Interop")] object? _, + IAsyncOperationWithProgress? value); + + *result = ConvertToUnmanaged(null, operation).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT FlushAsync(void* thisPtr, void** result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IAsyncOperation operation = thisObject.FlushAsync(); + + [UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] + static extern WindowsRuntimeObjectReferenceValue ConvertToUnmanaged( + [UnsafeAccessorType("ABI.Windows.Foundation.<#CsWinRT>IAsyncOperation'1Marshaller, WinRT.Interop")] object? _, + IAsyncOperation? value); + + *result = ConvertToUnmanaged(null, operation).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } +} + +/// +/// The implementation for . +/// +[DynamicInterfaceCastableImplementation] +[Guid("905A0FE6-BC53-11DF-8C49-001E4FC686DA")] +file interface IOutputStreamInterfaceImpl : IOutputStream +{ + /// + IAsyncOperationWithProgress IOutputStream.WriteAsync(IBuffer buffer) + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IOutputStream).TypeHandle); + + return IOutputStreamMethods.WriteAsync(thisReference, buffer); + } + + /// + IAsyncOperation IOutputStream.FlushAsync() + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IOutputStream).TypeHandle); + + return IOutputStreamMethods.FlushAsync(thisReference); + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IRandomAccessStream.cs b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IRandomAccessStream.cs new file mode 100644 index 000000000..7be716954 --- /dev/null +++ b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IRandomAccessStream.cs @@ -0,0 +1,584 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Storage.Streams; +using WindowsRuntime; +using WindowsRuntime.InteropServices; +using WindowsRuntime.InteropServices.Marshalling; +using static System.Runtime.InteropServices.ComWrappers; + +#pragma warning disable CA2256, IDE0008, IDE1006 + +#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code +[assembly: TypeMap( + value: "Windows.Storage.Streams.IRandomAccessStream", + target: typeof(IRandomAccessStream), + trimTarget: typeof(IRandomAccessStream))] +#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code + +[assembly: TypeMapAssociation( + source: typeof(IRandomAccessStream), + proxy: typeof(ABI.Windows.Storage.Streams.IRandomAccessStreamInterfaceImpl))] + +namespace ABI.Windows.Storage.Streams; + +/// +/// Marshaller for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IRandomAccessStreamMarshaller +{ + /// + public static WindowsRuntimeObjectReferenceValue ConvertToUnmanaged(IRandomAccessStream? value) + { + return WindowsRuntimeInterfaceMarshaller.ConvertToUnmanaged(value, in WellKnownWindowsInterfaceIIDs.IID_IRandomAccessStream); + } + + /// + public static IRandomAccessStream? ConvertToManaged(void* value) + { + return (IRandomAccessStream?)WindowsRuntimeObjectMarshaller.ConvertToManaged(value); + } +} + +/// +/// Interop methods for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IRandomAccessStreamMethods +{ + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static bool CanRead(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + bool result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->get_CanRead(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static bool CanWrite(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + bool result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->get_CanWrite(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong Position(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + ulong result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->get_Position(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong Size(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + ulong result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->get_Size(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + return result; + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Size(WindowsRuntimeObjectReference thisReference, ulong value) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->put_Size(thisPtr, value); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IInputStream GetInputStreamAt(WindowsRuntimeObjectReference thisReference, ulong position) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->GetInputStreamAt( + thisPtr, + position, + &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + return IInputStreamMarshaller.ConvertToManaged(result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IOutputStream GetOutputStreamAt(WindowsRuntimeObjectReference thisReference, ulong position) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->GetOutputStreamAt( + thisPtr, + position, + &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + return IOutputStreamMarshaller.ConvertToManaged(result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Seek(WindowsRuntimeObjectReference thisReference, ulong position) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->Seek(thisPtr, position); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + } + + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static IRandomAccessStream CloneStream(WindowsRuntimeObjectReference thisReference) + { + using WindowsRuntimeObjectReferenceValue thisValue = thisReference.AsValue(); + + void* thisPtr = thisValue.GetThisPtrUnsafe(); + void* result; + + HRESULT hresult = ((IRandomAccessStreamVftbl*)*(void***)thisPtr)->CloneStream(thisPtr, &result); + + RestrictedErrorInfo.ThrowExceptionForHR(hresult); + + try + { + return IRandomAccessStreamMarshaller.ConvertToManaged(result)!; + } + finally + { + WindowsRuntimeUnknownMarshaller.Free(result); + } + } +} + +/// +/// Binding type for . +/// +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct IRandomAccessStreamVftbl +{ + public delegate* unmanaged[MemberFunction] QueryInterface; + public delegate* unmanaged[MemberFunction] AddRef; + public delegate* unmanaged[MemberFunction] Release; + public delegate* unmanaged[MemberFunction] GetIids; + public delegate* unmanaged[MemberFunction] GetRuntimeClassName; + public delegate* unmanaged[MemberFunction] GetTrustLevel; + public delegate* unmanaged[MemberFunction] get_Size; + public delegate* unmanaged[MemberFunction] put_Size; + public delegate* unmanaged[MemberFunction] GetInputStreamAt; + public delegate* unmanaged[MemberFunction] GetOutputStreamAt; + public delegate* unmanaged[MemberFunction] get_Position; + public delegate* unmanaged[MemberFunction] Seek; + public delegate* unmanaged[MemberFunction] CloneStream; + public delegate* unmanaged[MemberFunction] get_CanRead; + public delegate* unmanaged[MemberFunction] get_CanWrite; +} + +/// +/// The implementation. +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class IRandomAccessStreamImpl +{ + /// + /// The value for the managed implementation. + /// + [FixedAddressValueType] + private static readonly IRandomAccessStreamVftbl Vftbl; + + /// + /// Initializes . + /// + static IRandomAccessStreamImpl() + { + *(IInspectableVftbl*)Unsafe.AsPointer(ref Vftbl) = *(IInspectableVftbl*)IInspectableImpl.Vtable; + + Vftbl.get_Size = &get_Size; + Vftbl.put_Size = &put_Size; + Vftbl.GetInputStreamAt = &GetInputStreamAt; + Vftbl.GetOutputStreamAt = &GetOutputStreamAt; + Vftbl.get_Position = &get_Position; + Vftbl.Seek = &Seek; + Vftbl.CloneStream = &CloneStream; + Vftbl.get_CanRead = &get_CanRead; + Vftbl.get_CanWrite = &get_CanWrite; + } + + /// + /// Gets a pointer to the managed implementation. + /// + public static nint Vtable + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => (nint)Unsafe.AsPointer(in Vftbl); + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_Size(void* thisPtr, ulong* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.Size; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT put_Size(void* thisPtr, ulong value) + { + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + thisObject.Size = value; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT GetInputStreamAt(void* thisPtr, ulong position, void** result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IInputStream inputStream = thisObject.GetInputStreamAt(position); + + *result = IInputStreamMarshaller.ConvertToUnmanaged(inputStream).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT GetOutputStreamAt(void* thisPtr, ulong position, void** result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IOutputStream outputStream = thisObject.GetOutputStreamAt(position); + + *result = IOutputStreamMarshaller.ConvertToUnmanaged(outputStream).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_Position(void* thisPtr, ulong* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.Position; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT Seek(void* thisPtr, ulong position) + { + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + thisObject.Seek(position); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT CloneStream(void* thisPtr, void** result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + IRandomAccessStream clonedStream = thisObject.CloneStream(); + + *result = IRandomAccessStreamMarshaller.ConvertToUnmanaged(clonedStream).DetachThisPtrUnsafe(); + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_CanRead(void* thisPtr, bool* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.CanRead; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] + private static HRESULT get_CanWrite(void* thisPtr, bool* result) + { + if (result is null) + { + return WellKnownErrorCodes.E_POINTER; + } + + try + { + var thisObject = ComInterfaceDispatch.GetInstance((ComInterfaceDispatch*)thisPtr); + + *result = thisObject.CanWrite; + + return WellKnownErrorCodes.S_OK; + } + catch (Exception e) + { + return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); + } + } +} + +/// +/// The implementation for . +/// +[DynamicInterfaceCastableImplementation] +[Guid("905A0FE1-BC53-11DF-8C49-001E4FC686DA")] +file interface IRandomAccessStreamInterfaceImpl : IRandomAccessStream +{ + /// + bool IRandomAccessStream.CanRead + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.CanRead(thisReference); + } + } + + /// + bool IRandomAccessStream.CanWrite + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.CanWrite(thisReference); + } + } + + /// + ulong IRandomAccessStream.Position + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.Position(thisReference); + } + } + + /// + ulong IRandomAccessStream.Size + { + get + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.Size(thisReference); + } + set + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + IRandomAccessStreamMethods.Size(thisReference, value); + } + } + + /// + IInputStream IRandomAccessStream.GetInputStreamAt(ulong position) + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.GetInputStreamAt(thisReference, position); + } + + /// + IOutputStream IRandomAccessStream.GetOutputStreamAt(ulong position) + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.GetOutputStreamAt(thisReference, position); + } + + /// + void IRandomAccessStream.Seek(ulong position) + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + IRandomAccessStreamMethods.Seek(thisReference, position); + } + + /// + IRandomAccessStream IRandomAccessStream.CloneStream() + { + var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IRandomAccessStream).TypeHandle); + + return IRandomAccessStreamMethods.CloneStream(thisReference); + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/InputStreamOptions.cs b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/InputStreamOptions.cs new file mode 100644 index 000000000..fdb05a299 --- /dev/null +++ b/src/WinRT.Runtime2/ABI/Windows.Storage.Streams/InputStreamOptions.cs @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Windows.Storage.Streams; +using WindowsRuntime; +using WindowsRuntime.InteropServices; +using WindowsRuntime.InteropServices.Marshalling; +using static System.Runtime.InteropServices.ComWrappers; + +#pragma warning disable IDE1006, CA1416 + +#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code +[assembly: TypeMap( + value: "Windows.Storage.Streams.InputStreamOptions", + target: typeof(InputStreamOptions), + trimTarget: typeof(InputStreamOptions))] + +[assembly: TypeMap( + value: "Windows.Foundation.IReference`1", + target: typeof(InputStreamOptions), + trimTarget: typeof(InputStreamOptions))] +#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code + +namespace ABI.Windows.Storage.Streams; + +/// +/// Marshaller for . +/// +[Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, + DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, + UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] +[EditorBrowsable(EditorBrowsableState.Never)] +public static unsafe class InputStreamOptionsMarshaller +{ + /// + public static WindowsRuntimeObjectReferenceValue BoxToUnmanaged(InputStreamOptions? value) + { + return WindowsRuntimeValueTypeMarshaller.BoxToUnmanaged(value, CreateComInterfaceFlags.None, in WellKnownWindowsInterfaceIIDs.IID_IReferenceOfInputStreamOptions); + } + + /// + public static InputStreamOptions? UnboxToManaged(void* value) + { + return WindowsRuntimeValueTypeMarshaller.UnboxToManaged(value); + } +} + +/// +/// The set of values for . +/// +file struct InputStreamOptionsInterfaceEntries +{ + public ComInterfaceEntry IReferenceOfInputStreamOptions; + public ComInterfaceEntry IPropertyValue; + public ComInterfaceEntry IStringable; + public ComInterfaceEntry IWeakReferenceSource; + public ComInterfaceEntry IMarshal; + public ComInterfaceEntry IAgileObject; + public ComInterfaceEntry IInspectable; + public ComInterfaceEntry IUnknown; +} + +/// +/// The implementation of . +/// +file static class InputStreamOptionsInterfaceEntriesImpl +{ + /// + /// The value for . + /// + [FixedAddressValueType] + public static readonly InputStreamOptionsInterfaceEntries Entries; + + /// + /// Initializes . + /// + static InputStreamOptionsInterfaceEntriesImpl() + { + Entries.IReferenceOfInputStreamOptions.IID = WellKnownWindowsInterfaceIIDs.IID_IReferenceOfInputStreamOptions; + Entries.IReferenceOfInputStreamOptions.Vtable = IReferenceImpl.UInt32Enum; + Entries.IPropertyValue.IID = WellKnownWindowsInterfaceIIDs.IID_IPropertyValue; + Entries.IPropertyValue.Vtable = IPropertyValueImpl.OtherTypeVtable; + Entries.IStringable.IID = WellKnownWindowsInterfaceIIDs.IID_IStringable; + Entries.IStringable.Vtable = IStringableImpl.Vtable; + Entries.IWeakReferenceSource.IID = WellKnownWindowsInterfaceIIDs.IID_IWeakReferenceSource; + Entries.IWeakReferenceSource.Vtable = IWeakReferenceSourceImpl.Vtable; + Entries.IMarshal.IID = WellKnownWindowsInterfaceIIDs.IID_IMarshal; + Entries.IMarshal.Vtable = IMarshalImpl.Vtable; + Entries.IAgileObject.IID = WellKnownWindowsInterfaceIIDs.IID_IAgileObject; + Entries.IAgileObject.Vtable = IAgileObjectImpl.Vtable; + Entries.IInspectable.IID = WellKnownWindowsInterfaceIIDs.IID_IInspectable; + Entries.IInspectable.Vtable = IInspectableImpl.Vtable; + Entries.IUnknown.IID = WellKnownWindowsInterfaceIIDs.IID_IUnknown; + Entries.IUnknown.Vtable = IUnknownImpl.Vtable; + } +} + +/// +/// A custom implementation for . +/// +internal sealed unsafe class InputStreamOptionsComWrappersMarshallerAttribute : WindowsRuntimeComWrappersMarshallerAttribute +{ + /// + public override void* GetOrCreateComInterfaceForObject(object value) + { + return WindowsRuntimeComWrappersMarshal.GetOrCreateComInterfaceForObject(value, CreateComInterfaceFlags.None); + } + + /// + public override ComInterfaceEntry* ComputeVtables(out int count) + { + count = sizeof(InputStreamOptionsInterfaceEntries) / sizeof(ComInterfaceEntry); + + return (ComInterfaceEntry*)Unsafe.AsPointer(in InputStreamOptionsInterfaceEntriesImpl.Entries); + } + + /// + public override object CreateObject(void* value, out CreatedWrapperFlags wrapperFlags) + { + wrapperFlags = CreatedWrapperFlags.NonWrapping; + + return WindowsRuntimeValueTypeMarshaller.UnboxToManagedUnsafe(value, in WellKnownWindowsInterfaceIIDs.IID_IReferenceOfInputStreamOptions); + } +} \ No newline at end of file diff --git a/src/WinRT.Runtime2/Bindables/WindowsRuntimeEnumerator.cs b/src/WinRT.Runtime2/Bindables/WindowsRuntimeEnumerator.cs index 428ed44b1..d0a4312bc 100644 --- a/src/WinRT.Runtime2/Bindables/WindowsRuntimeEnumerator.cs +++ b/src/WinRT.Runtime2/Bindables/WindowsRuntimeEnumerator.cs @@ -61,7 +61,7 @@ public object? Current throw new InvalidOperationException("InvalidOperation_EnumEnded"); } - return field!; + return field; } private set; } diff --git a/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs index 01be60c17..41e3c32a5 100644 --- a/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs @@ -135,7 +135,7 @@ public Enumerator(IEnumerable> enumerable) } /// - public TKey Current => _enumerator!.Current.Key; + public TKey Current => _enumerator.Current.Key; /// object IEnumerator.Current => Current!; diff --git a/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs index 11b4bd25a..b382430ed 100644 --- a/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs @@ -144,7 +144,7 @@ public Enumerator(IEnumerable> enumerable) } /// - public TValue Current => _enumerator!.Current.Value; + public TValue Current => _enumerator.Current.Value; /// object IEnumerator.Current => Current!; diff --git a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs index c93854e0c..7b9ef3047 100644 --- a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs @@ -78,7 +78,7 @@ public Enumerator(IEnumerable> enumerable) } /// - public TKey Current => _enumerator!.Current.Key; + public TKey Current => _enumerator.Current.Key; /// object IEnumerator.Current => Current!; diff --git a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs index 7c6b90715..00ed96700 100644 --- a/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs @@ -78,7 +78,7 @@ public Enumerator(IEnumerable> enumerable) } /// - public TValue Current => _enumerator!.Current.Value; + public TValue Current => _enumerator.Current.Value; /// object IEnumerator.Current => Current!; diff --git a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs index 6019439e6..ea2737327 100644 --- a/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs +++ b/src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs @@ -8,7 +8,7 @@ using System.Diagnostics.CodeAnalysis; using WindowsRuntime.InteropServices; -#pragma warning disable CA1816, IDE0046 +#pragma warning disable CS9264, CA1816, IDE0046 namespace WindowsRuntime; @@ -70,7 +70,7 @@ public T Current throw new InvalidOperationException("InvalidOperation_EnumEnded"); } - return field!; + return field; } private set; } diff --git a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionarySplitAdapter{TKey, TValue}.cs b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionarySplitAdapter{TKey, TValue}.cs index aeb2ebd97..1eda80045 100644 --- a/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionarySplitAdapter{TKey, TValue}.cs +++ b/src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionarySplitAdapter{TKey, TValue}.cs @@ -99,7 +99,7 @@ public TValue this[TKey key] ThrowKeyNotFoundException(); } - return value!; + return value; } } diff --git a/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.g.cs b/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.g.cs index 2a52094ec..2ca6a8e85 100644 --- a/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.g.cs +++ b/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.g.cs @@ -204,4 +204,32 @@ public static ref readonly Guid IID_Windows_Foundation_IAsyncInfo [MethodImpl(MethodImplOptions.AggressiveInlining)] get => ref WellKnownWindowsInterfaceIIDs.IID_IAsyncInfo; } + + /// The IID for Windows.Storage.Streams.IBuffer (mapped to . + public static ref readonly Guid IID_Windows_Storage_Streams_IBuffer + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref WellKnownWindowsInterfaceIIDs.IID_IBuffer; + } + + /// The IID for Windows.Storage.Streams.IInputStream (mapped to . + public static ref readonly Guid IID_Windows_Storage_Streams_IInputStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref WellKnownWindowsInterfaceIIDs.IID_IInputStream; + } + + /// The IID for Windows.Storage.Streams.IOutputStream (mapped to . + public static ref readonly Guid IID_Windows_Storage_Streams_IOutputStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref WellKnownWindowsInterfaceIIDs.IID_IOutputStream; + } + + /// The IID for Windows.Storage.Streams.IRandomAccessStream (mapped to . + public static ref readonly Guid IID_Windows_Storage_Streams_IRandomAccessStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => ref WellKnownWindowsInterfaceIIDs.IID_IRandomAccessStream; + } } \ No newline at end of file diff --git a/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.tt b/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.tt index 805aa7672..6ddf0ca64 100644 --- a/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.tt +++ b/src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.tt @@ -49,7 +49,11 @@ var entries = new (string ProjectedFullyQualifiedName, string WindowsRuntimeFull ("System.Windows.Input.ICommand", "Microsoft.UI.Xaml.Input.ICommand", false), ("Windows.Foundation.Collections.IVectorChangedEventArgs", null, false), ("Windows.Foundation.IAsyncAction", null, false), - ("Windows.Foundation.IAsyncInfo", null, false) + ("Windows.Foundation.IAsyncInfo", null, false), + ("Windows.Storage.Streams.IBuffer", null, false), + ("Windows.Storage.Streams.IInputStream", null, false), + ("Windows.Storage.Streams.IOutputStream", null, false), + ("Windows.Storage.Streams.IRandomAccessStream", null, false), }; for (int i = 0; i < entries.Length; i++) diff --git a/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.g.cs b/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.g.cs index 30a8be4b8..a07806bcc 100644 --- a/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.g.cs +++ b/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.g.cs @@ -310,6 +310,81 @@ public static ref readonly Guid IID_IMemoryBufferByteAccess } } + /// The IID for IInputStream (905A0FE2-BC53-11DF-8C49-001E4FC686DA). + public static ref readonly Guid IID_IInputStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = + [ + 0xE2, 0x0F, 0x5A, 0x90, + 0x53, 0xBC, + 0xDF, 0x11, + 0x8C, + 0x49, + 0x00, + 0x1E, + 0x4F, + 0xC6, + 0x86, + 0xDA + ]; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + + /// The IID for IOutputStream (905A0FE6-BC53-11DF-8C49-001E4FC686DA). + public static ref readonly Guid IID_IOutputStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = + [ + 0xE6, 0x0F, 0x5A, 0x90, + 0x53, 0xBC, + 0xDF, 0x11, + 0x8C, + 0x49, + 0x00, + 0x1E, + 0x4F, + 0xC6, + 0x86, + 0xDA + ]; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + + /// The IID for IRandomAccessStream (905A0FE1-BC53-11DF-8C49-001E4FC686DA). + public static ref readonly Guid IID_IRandomAccessStream + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = + [ + 0xE1, 0x0F, 0x5A, 0x90, + 0x53, 0xBC, + 0xDF, 0x11, + 0x8C, + 0x49, + 0x00, + 0x1E, + 0x4F, + 0xC6, + 0x86, + 0xDA + ]; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + /// The IID for IContextCallback (000001DA-0000-0000-C000-000000000046). public static ref readonly Guid IID_IContextCallback { @@ -2310,6 +2385,31 @@ public static ref readonly Guid IID_IReferenceOfCollectionChange } } + /// The IID for IReferenceOfInputStreamOptions (AEA3CA95-06D3-5B19-A94D-907D1E6BCF18). + public static ref readonly Guid IID_IReferenceOfInputStreamOptions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = + [ + 0x95, 0xCA, 0xA3, 0xAE, + 0xD3, 0x06, + 0x19, 0x5B, + 0xA9, + 0x4D, + 0x90, + 0x7D, + 0x1E, + 0x6B, + 0xCF, + 0x18 + ]; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + /// The IID for IReferenceArrayOfInt32 (A6D080A5-B087-5BC2-9A9F-5CD687B4D1F7). public static ref readonly Guid IID_IReferenceArrayOfInt32 { diff --git a/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.tt b/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.tt index 3cd1bce81..0ecfcde1c 100644 --- a/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.tt +++ b/src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.tt @@ -29,6 +29,9 @@ var entries = new (string Name, string IID)[] ("IBuffer", "905A0FE0-BC53-11DF-8C49-001E4FC686DA"), ("IBufferByteAccess", "905A0FEF-BC53-11DF-8C49-001E4FC686DA"), ("IMemoryBufferByteAccess", "5B0D3235-4DBA-4D44-865E-8F1D0E4FD04D"), + ("IInputStream", "905A0FE2-BC53-11DF-8C49-001E4FC686DA"), + ("IOutputStream", "905A0FE6-BC53-11DF-8C49-001E4FC686DA"), + ("IRandomAccessStream", "905A0FE1-BC53-11DF-8C49-001E4FC686DA"), ("IContextCallback", "000001DA-0000-0000-C000-000000000046"), ("ICallbackWithNoReentrancyToApplicationSTA", "0A299774-3E4E-FC42-1D9D-72CEE105CA57"), ("IErrorInfo", "1CF2B120-547D-101B-8E65-08002B2BD119"), @@ -109,6 +112,7 @@ var entries = new (string Name, string IID)[] ("IReferenceOfAsyncStatus", "A4B74936-2947-5FE8-88D5-51CD35050E71"), ("IReferenceOfAsyncActionCompletedHandler", "F31DBB29-606D-5A89-A23A-C09AB9605B8F"), ("IReferenceOfCollectionChange", "25BCAF91-880D-537D-82FC-9BBF0CACCB8B"), + ("IReferenceOfInputStreamOptions", "AEA3CA95-06D3-5B19-A94D-907D1E6BCF18"), ("IReferenceArrayOfInt32", "A6D080A5-B087-5BC2-9A9F-5CD687B4D1F7"), ("IReferenceArrayOfString", "0385688E-E3C7-5C5E-A389-5524EDE349F1"), ("IReferenceArrayOfByte", "2AF22683-3734-56D0-A60E-688CC85D1619"), diff --git a/src/WinRT.Runtime2/Windows.Foundation/UniversalApiContract.cs b/src/WinRT.Runtime2/Windows.Foundation/UniversalApiContract.cs new file mode 100644 index 000000000..577adb7bb --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Foundation/UniversalApiContract.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using Windows.Foundation.Metadata; + +namespace Windows.Foundation; + +/// +/// Represents the Universal API contract. +/// +/// +/// This type is required for ABI projection of the value types and delegates, but marshalling it is not supported. +/// +[ContractVersion(1245184u)] +public enum UniversalApiContract; \ No newline at end of file diff --git a/src/WinRT.Runtime2/Windows.Storage.Streams/IBuffer.cs b/src/WinRT.Runtime2/Windows.Storage.Streams/IBuffer.cs new file mode 100644 index 000000000..86642d7f5 --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Storage.Streams/IBuffer.cs @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Foundation.Metadata; +using WindowsRuntime; + +namespace Windows.Storage.Streams; + +/// +/// Represents a referenced array of bytes used by byte stream read and write interfaces. +/// +[WindowsRuntimeMetadata("Windows.Foundation.UniversalApiContract")] +[Guid("905A0FE0-BC53-11DF-8C49-001E4FC686DA")] +[ContractVersion(typeof(UniversalApiContract), 65536u)] +public interface IBuffer +{ + /// + /// Gets the maximum number of bytes that the buffer can hold. + /// + uint Capacity { get; } + + /// + /// Gets the number of bytes currently in use in the buffer. + /// + uint Length { get; set; } +} diff --git a/src/WinRT.Runtime2/Windows.Storage.Streams/IInputStream.cs b/src/WinRT.Runtime2/Windows.Storage.Streams/IInputStream.cs new file mode 100644 index 000000000..b6e53c825 --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Storage.Streams/IInputStream.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Foundation.Metadata; +using WindowsRuntime; + +namespace Windows.Storage.Streams; + +/// +/// Represents a sequential stream of bytes to be read. +/// +[WindowsRuntimeMetadata("Windows.Foundation.UniversalApiContract")] +[Guid("905A0FE2-BC53-11DF-8C49-001E4FC686DA")] +[ContractVersion(typeof(UniversalApiContract), 65536u)] +public interface IInputStream : IDisposable +{ + /// + /// Reads data from the stream asynchronously. + /// + /// A buffer that may be used to return the bytes that are read. The return value contains the buffer that holds the results. + /// The number of bytes to read that is less than or equal to the value. + /// Specifies the type of the asynchronous read operation. + /// The asynchronous operation. + /// + /// + /// Always read data from the buffer returned in the . Don't assume that the + /// input buffer contains the data. Depending on the implementation, the data that's read might be placed into the input buffer, or it might + /// be returned in a different buffer. For the input buffer, you don't have to implement the interface. Instead, you + /// can create an instance of the Buffer class. + /// + /// + /// Also consider reading a buffer into an by using the + /// ReadBuffer method of the + /// DataReader class. + /// + /// + IAsyncOperationWithProgress ReadAsync(IBuffer buffer, uint count, InputStreamOptions options); +} diff --git a/src/WinRT.Runtime2/Windows.Storage.Streams/IOutputStream.cs b/src/WinRT.Runtime2/Windows.Storage.Streams/IOutputStream.cs new file mode 100644 index 000000000..fba084aa8 --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Storage.Streams/IOutputStream.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Foundation.Metadata; +using WindowsRuntime; + +namespace Windows.Storage.Streams; + +/// +/// Represents a sequential stream of bytes to be written. +/// +[WindowsRuntimeMetadata("Windows.Foundation.UniversalApiContract")] +[Guid("905A0FE6-BC53-11DF-8C49-001E4FC686DA")] +[ContractVersion(typeof(UniversalApiContract), 65536u)] +public interface IOutputStream : IDisposable +{ + /// + /// Writes data asynchronously in a sequential stream. + /// + /// A buffer that contains the data to be written. + /// + /// The byte writer operation. The first integer represents the number of bytes written. + /// The second integer represents the progress of the write operation. + /// + /// + /// + /// Some stream implementations support queuing of write operations. In this case, the asynchronous execution of the method does not complete until + /// the method has completed. For the buffer parameter, you don't have to implement the interface. Instead, you can create an + /// instance of the Buffer class or create a buffer by using methods in the + /// CryptographicBuffer class. + /// + /// + /// Also consider writing a buffer into an by using the + /// WriteBuffer method of the + /// DataWriter class. + /// + /// + IAsyncOperationWithProgress WriteAsync(IBuffer buffer); + + /// + /// Flushes data asynchronously in a sequential stream. + /// + /// The stream flush operation. + /// + /// The method improves, but does not guarantee durable and coherent storage of data, + /// and it introduces latencies. It's generally recommended to avoid this method to achieve good performance, + /// but it should be used if coherency is desired. + /// + IAsyncOperation FlushAsync(); +} diff --git a/src/WinRT.Runtime2/Windows.Storage.Streams/IRandomAccessStream.cs b/src/WinRT.Runtime2/Windows.Storage.Streams/IRandomAccessStream.cs new file mode 100644 index 000000000..35ec70bb8 --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Storage.Streams/IRandomAccessStream.cs @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.InteropServices; +using Windows.Foundation; +using Windows.Foundation.Metadata; +using WindowsRuntime; + +namespace Windows.Storage.Streams; + +/// +/// Supports random access of data in input and output streams. +/// +[WindowsRuntimeMetadata("Windows.Foundation.UniversalApiContract")] +[Guid("905A0FE1-BC53-11DF-8C49-001E4FC686DA")] +[ContractVersion(typeof(UniversalApiContract), 65536u)] +public interface IRandomAccessStream : IDisposable, IInputStream, IOutputStream +{ + /// + /// Gets a value that indicates whether the stream can be read from. + /// + bool CanRead { get; } + + /// + /// Gets a value that indicates whether the stream can be written to. + /// + bool CanWrite { get; } + + /// + /// Gets the byte offset of the stream. + /// + /// + /// + /// The initial offset of an is 0. + /// + /// + /// This offset is affected by both and operations. + /// + /// + ulong Position { get; } + + /// + /// Gets or sets the size of the random access stream. + /// + ulong Size { get; set; } + + /// + /// Returns an input stream at a specified location in a stream. + /// + /// The location in the stream at which to begin. + /// The input stream. + IInputStream GetInputStreamAt(ulong position); + + /// + /// Returns an output stream at a specified location in a stream. + /// + /// The location in the output stream at which to begin. + /// The output stream. + IOutputStream GetOutputStreamAt(ulong position); + + /// + /// Sets the position of the stream to the specified value. + /// + /// The new position of the stream. + /// + /// This method does not check the position to make sure the value is valid for the stream. If the position is + /// invalid for the stream, the and + /// methods will return an error when called. + /// + void Seek(ulong position); + + /// + /// Creates a new instance of an over the same resource as the current stream. + /// + /// The new stream. The initial, internal position of the stream is 0. + /// + /// The internal position and lifetime of this new stream are independent from the position and lifetime of the cloned stream. + /// + IRandomAccessStream CloneStream(); +} diff --git a/src/WinRT.Runtime2/Windows.Storage.Streams/InputStreamOptions.cs b/src/WinRT.Runtime2/Windows.Storage.Streams/InputStreamOptions.cs new file mode 100644 index 000000000..c295319a7 --- /dev/null +++ b/src/WinRT.Runtime2/Windows.Storage.Streams/InputStreamOptions.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using System.Runtime.Versioning; +using Windows.Foundation; +using Windows.Foundation.Metadata; +using WindowsRuntime; + +namespace Windows.Storage.Streams; + +/// +/// Specifies the read options for an input stream. +/// +/// +[Flags] +[WindowsRuntimeMetadata("Windows.Foundation.UniversalApiContract")] +[WindowsRuntimeClassName("Windows.Foundation.IReference`1")] +[WindowsRuntimeReferenceType(typeof(InputStreamOptions?))] +[SupportedOSPlatform("Windows10.0.10240.0")] +[ContractVersion(typeof(UniversalApiContract), 65536u)] +[ABI.Windows.Storage.Streams.InputStreamOptionsComWrappersMarshaller] +public enum InputStreamOptions : uint +{ + /// + /// No options are specified. + /// + None = 0u, + + /// + /// The asynchronous read operation completes when one or more bytes is available. + /// + Partial = 1u, + + /// + /// The asynchronous read operation may optionally read ahead and prefetch additional bytes. + /// + ReadAhead = 2u +} diff --git a/src/cswinrt/helpers.h b/src/cswinrt/helpers.h index 6e171e50c..6cd6c4fbb 100644 --- a/src/cswinrt/helpers.h +++ b/src/cswinrt/helpers.h @@ -775,7 +775,7 @@ namespace cswinrt }, { "Microsoft.UI.Xaml.Input", { - { "ICommand", "System.Windows.Input", "ICommand", true } + { "ICommand", "System.Windows.Input", "ICommand", true }, } }, { "Microsoft.UI.Xaml.Interop", @@ -852,7 +852,8 @@ namespace cswinrt { "Size", "Windows.Foundation", "Size" }, { "TimeSpan", "System", "TimeSpan", true }, { "TypedEventHandler`2", "System", "EventHandler`2", false }, - { "Uri", "System", "Uri", true } + { "UniversalApiContract", "Windows.Foundation", "UniversalApiContract"}, + { "Uri", "System", "Uri", true }, } }, { "Windows.Foundation.Collections", @@ -870,14 +871,14 @@ namespace cswinrt { "IVectorView`1", "System.Collections.Generic", "IReadOnlyList`1", true, true }, { "IVector`1", "System.Collections.Generic", "IList`1", true, true }, { "MapChangedEventHandler`2", "Windows.Foundation.Collections", "MapChangedEventHandler`2" }, - { "VectorChangedEventHandler`1", "Windows.Foundation.Collections", "VectorChangedEventHandler`1" } + { "VectorChangedEventHandler`1", "Windows.Foundation.Collections", "VectorChangedEventHandler`1" }, } }, { "Windows.Foundation.Metadata", { { "AttributeTargets", "System", "AttributeTargets" }, { "AttributeUsageAttribute", "System", "AttributeUsageAttribute" }, - { "ContractVersionAttribute", "Windows.Foundation.Metadata", "ContractVersionAttribute"} + { "ContractVersionAttribute", "Windows.Foundation.Metadata", "ContractVersionAttribute"}, } }, { "Windows.Foundation.Numerics", @@ -891,6 +892,15 @@ namespace cswinrt { "Vector4", "System.Numerics", "Vector4" }, } }, + { "Windows.Storage.Streams", + { + { "IBuffer", "Windows.Storage.Streams", "IBuffer" }, + { "IInputStream", "Windows.Storage.Streams", "IInputStream" }, + { "IOutputStream", "Windows.Storage.Streams", "IOutputStream" }, + { "IRandomAccessStream", "Windows.Storage.Streams", "IRandomAccessStream" }, + { "InputStreamOptions", "Windows.Storage.Streams", "InputStreamOptions" }, + } + }, { "Windows.UI.Xaml", { { "CornerRadius", "Windows.UI.Xaml", "CornerRadius", false, false, true }, @@ -929,7 +939,7 @@ namespace cswinrt }, { "Windows.UI.Xaml.Input", { - { "ICommand", "System.Windows.Input", "ICommand", true } + { "ICommand", "System.Windows.Input", "ICommand", true }, } }, { "Windows.UI.Xaml.Interop", @@ -942,7 +952,7 @@ namespace cswinrt { "NotifyCollectionChangedEventArgs", "System.Collections.Specialized", "NotifyCollectionChangedEventArgs", true }, { "NotifyCollectionChangedEventHandler", "System.Collections.Specialized", "NotifyCollectionChangedEventHandler", true }, { "TypeKind", "Windows.UI.Xaml.Interop", "TypeKind", true }, - { "TypeName", "System", "Type", true } + { "TypeName", "System", "Type", true }, } }, { "Windows.UI.Xaml.Media", diff --git a/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBuffer.cs b/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBuffer.cs index 6d1be03c0..1a522bcb2 100644 --- a/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBuffer.cs +++ b/src/cswinrt/strings/additions/Windows.Storage.Streams/WindowsRuntimeBuffer.cs @@ -246,7 +246,7 @@ file static class WindowsRuntimeBufferInterfaceEntriesImpl /// static WindowsRuntimeBufferInterfaceEntriesImpl() { - Entries.IBuffer.IID = global::ABI.InterfaceIIDs.IID_Windows_Storage_Streams_IBuffer; + Entries.IBuffer.IID = global::WindowsRuntime.InteropServices.WellKnownInterfaceIIDs.IID_Windows_Storage_Streams_IBuffer; Entries.IBuffer.Vtable = global::ABI.Windows.Storage.Streams.IBufferImpl.Vtable; Entries.IBufferByteAccess.IID = global::WindowsRuntime.InteropServices.WellKnownInterfaceIIDs.IID_IBufferByteAccess; Entries.IBufferByteAccess.Vtable = global::ABI.Windows.Storage.Streams.IBufferByteAccessImpl.Vtable;