-
Notifications
You must be signed in to change notification settings - Fork 123
Manually project basic 'Windows.Storage.Stream' types in 'WinRT.Runtime.dll' #2250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sergio0694
wants to merge
23
commits into
staging/3.0
Choose a base branch
from
user/sergiopedri/stream-interfaces
base: staging/3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e1cc204
Add UniversalApiContract enum and mapping
Sergio0694 386c656
Add IBuffer interface and register mapping
Sergio0694 aae7583
Add ABI marshalling for IBuffer
Sergio0694 651fe4f
Add IBuffer interop references and IID
Sergio0694 0c6cbd8
Add InputStreamOptions enum for WinRT runtime
Sergio0694 f7bf1f2
Add InputStreamOptions marshaller and IID
Sergio0694 4d39079
Add InputStreamOptions to interop references
Sergio0694 c2cb53f
Add IInputStream interface for WinRT streams
Sergio0694 4552952
Add ComWrappers marshaller to InputStreamOptions
Sergio0694 2298df0
Add IInputStream ABI marshaller and IID
Sergio0694 3b5bf5c
Add IOutputStream interface
Sergio0694 760fbbc
Add IOutputStream marshaller and IID
Sergio0694 03d1548
Add IInputStream and IOutputStream WinRT refs
Sergio0694 bd09477
Add IRandomAccessStream interface
Sergio0694 349f618
Add IRandomAccessStream marshalling and IID
Sergio0694 9b05aaa
Add IRandomAccessStream support
Sergio0694 5ce2da4
Update GUIDs for Windows.Storage.Streams interfaces
Sergio0694 6df8974
Remove unnecessary null-forgiving operators
Sergio0694 885b6ca
Suppress CS9264 in WindowsRuntimeEnumerator
Sergio0694 ca0a0ee
Fix IID for IReferenceOfInputStreamOptions
Sergio0694 53fbaa3
Fix typo
Sergio0694 badfd58
Add Storage.Streams interface IIDs
Sergio0694 130ee69
Use WellKnownInterfaceIIDs for IBuffer IID
Sergio0694 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
259 changes: 259 additions & 0 deletions
259
src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IBuffer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<WindowsRuntimeMetadataTypeMapGroup>( | ||
| 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<DynamicInterfaceCastableImplementationTypeMapGroup>( | ||
| source: typeof(IBuffer), | ||
| proxy: typeof(ABI.Windows.Storage.Streams.IBufferInterfaceImpl))] | ||
|
|
||
| namespace ABI.Windows.Storage.Streams; | ||
|
|
||
| /// <summary> | ||
| /// Marshaller for <see cref="IBuffer"/>. | ||
| /// </summary> | ||
| [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, | ||
| DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, | ||
| UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public static unsafe class IBufferMarshaller | ||
| { | ||
| /// <inheritdoc cref="WindowsRuntimeObjectMarshaller.ConvertToUnmanaged"/> | ||
| public static WindowsRuntimeObjectReferenceValue ConvertToUnmanaged(IBuffer? value) | ||
| { | ||
| return WindowsRuntimeInterfaceMarshaller<IBuffer>.ConvertToUnmanaged(value, in WellKnownWindowsInterfaceIIDs.IID_IBuffer); | ||
| } | ||
|
|
||
| /// <inheritdoc cref="WindowsRuntimeDelegateMarshaller.ConvertToManaged"/> | ||
| public static IBuffer? ConvertToManaged(void* value) | ||
| { | ||
| return (IBuffer?)WindowsRuntimeObjectMarshaller.ConvertToManaged(value); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Interop methods for <see cref="IBuffer"/>. | ||
| /// </summary> | ||
| [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, | ||
| DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, | ||
| UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public static unsafe class IBufferMethods | ||
| { | ||
| /// <see cref="IBuffer.Capacity"/> | ||
| [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; | ||
| } | ||
|
|
||
| /// <see cref="IBuffer.Length"/> | ||
| [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; | ||
| } | ||
|
|
||
| /// <see cref="IBuffer.Length"/> | ||
| [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); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Binding type for <see cref="IBuffer"/>. | ||
| /// </summary> | ||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal unsafe struct IBufferVftbl | ||
| { | ||
| public delegate* unmanaged[MemberFunction]<void*, Guid*, void**, HRESULT> QueryInterface; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint> AddRef; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint> Release; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint*, Guid**, HRESULT> GetIids; | ||
| public delegate* unmanaged[MemberFunction]<void*, HSTRING*, HRESULT> GetRuntimeClassName; | ||
| public delegate* unmanaged[MemberFunction]<void*, TrustLevel*, HRESULT> GetTrustLevel; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint*, HRESULT> get_Capacity; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint*, HRESULT> get_Length; | ||
| public delegate* unmanaged[MemberFunction]<void*, uint, HRESULT> set_Length; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="IBuffer"/> implementation. | ||
| /// </summary> | ||
| [Obsolete(WindowsRuntimeConstants.PrivateImplementationDetailObsoleteMessage, | ||
| DiagnosticId = WindowsRuntimeConstants.PrivateImplementationDetailObsoleteDiagnosticId, | ||
| UrlFormat = WindowsRuntimeConstants.CsWinRTDiagnosticsUrlFormat)] | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| public static unsafe class IBufferImpl | ||
| { | ||
| /// <summary> | ||
| /// The <see cref="IBufferVftbl"/> value for the managed <see cref="IBuffer"/> implementation. | ||
| /// </summary> | ||
| [FixedAddressValueType] | ||
| private static readonly IBufferVftbl Vftbl; | ||
|
|
||
| /// <summary> | ||
| /// Initializes <see cref="Vftbl"/>. | ||
| /// </summary> | ||
| 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; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a pointer to the managed <see cref="IBuffer"/> implementation. | ||
| /// </summary> | ||
| public static nint Vtable | ||
| { | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| get => (nint)Unsafe.AsPointer(in Vftbl); | ||
| } | ||
|
|
||
| /// <see href="https://learn.microsoft.com/uwp/api/windows.storage.streams.ibuffer.capacity"/> | ||
| [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<IBuffer>((ComInterfaceDispatch*)thisPtr); | ||
|
|
||
| *result = thisObject.Capacity; | ||
|
|
||
| return WellKnownErrorCodes.S_OK; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); | ||
| } | ||
| } | ||
|
|
||
| /// <see href="https://learn.microsoft.com/uwp/api/windows.storage.streams.ibuffer.length"/> | ||
| [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<IBuffer>((ComInterfaceDispatch*)thisPtr); | ||
|
|
||
| *result = thisObject.Length; | ||
|
|
||
| return WellKnownErrorCodes.S_OK; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); | ||
| } | ||
| } | ||
|
|
||
| /// <see href="https://learn.microsoft.com/uwp/api/windows.storage.streams.ibuffer.length"/> | ||
| [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])] | ||
| private static HRESULT set_Length(void* thisPtr, uint value) | ||
| { | ||
| try | ||
| { | ||
| var thisObject = ComInterfaceDispatch.GetInstance<IBuffer>((ComInterfaceDispatch*)thisPtr); | ||
|
|
||
| thisObject.Length = value; | ||
|
|
||
| return WellKnownErrorCodes.S_OK; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| return RestrictedErrorInfoExceptionMarshaller.ConvertToUnmanaged(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The <see cref="IDynamicInterfaceCastable"/> implementation for <see cref="IBuffer"/>. | ||
| /// </summary> | ||
| [DynamicInterfaceCastableImplementation] | ||
| [Guid("905A0FE0-BC53-11DF-8C49-001E4FC686DA")] | ||
| file interface IBufferInterfaceImpl : IBuffer | ||
| { | ||
| /// <inheritdoc/> | ||
| uint IBuffer.Capacity | ||
| { | ||
| get | ||
| { | ||
| var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); | ||
|
|
||
| return IBufferMethods.Capacity(thisReference); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| uint IBuffer.Length | ||
| { | ||
| get | ||
| { | ||
| var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); | ||
Sergio0694 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return IBufferMethods.Length(thisReference); | ||
| } | ||
| set | ||
| { | ||
| var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle); | ||
Sergio0694 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| IBufferMethods.Length(thisReference, value); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.