Manually project basic 'Windows.Storage.Stream' types in 'WinRT.Runtime.dll'#2250
Open
Sergio0694 wants to merge 23 commits intostaging/3.0from
Open
Manually project basic 'Windows.Storage.Stream' types in 'WinRT.Runtime.dll'#2250Sergio0694 wants to merge 23 commits intostaging/3.0from
Sergio0694 wants to merge 23 commits intostaging/3.0from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR manually projects five types from the Windows.Storage.Streams namespace into WinRT.Runtime.dll, making them available for use without requiring code generation from metadata. The changes include both public interface definitions and their complete ABI marshalling infrastructure.
Changes:
- Added manual projections for
IBuffer,IInputStream,IOutputStream,IRandomAccessStream, andInputStreamOptionsenum - Added
UniversalApiContractenum to support contract versioning for the new types - Updated projection configuration in
helpers.hand type detection logic inWindowsRuntimeExtensions.cs
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| src/cswinrt/helpers.h | Added manual projection mappings for Windows.Storage.Streams types and UniversalApiContract, with trailing comma fixes |
| src/WinRT.Runtime2/Windows.Storage.Streams/*.cs | Public interface and enum definitions with XML documentation and attributes |
| src/WinRT.Runtime2/Windows.Foundation/UniversalApiContract.cs | Contract enum definition for API versioning |
| src/WinRT.Runtime2/ABI/Windows.Storage.Streams/*.cs | Complete ABI marshalling implementations including marshallers, vtables, and DynamicInterfaceCastable proxies |
| src/WinRT.Runtime2/InteropServices/WellKnownWindowsInterfaceIIDs.* | IID definitions for the new interfaces (template and generated files) |
| src/WinRT.Runtime2/InteropServices/WellKnownInterfaceIIDs.* | Added IBuffer to projected interface IIDs |
| src/WinRT.Interop.Generator/References/InteropReferences.cs | Added type references for code generation support |
| src/WinRT.Interop.Generator/Extensions/WindowsRuntimeExtensions.cs | Updated manual projection detection logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IOutputStream.cs
Outdated
Show resolved
Hide resolved
src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IRandomAccessStream.cs
Outdated
Show resolved
Hide resolved
src/WinRT.Runtime2/Windows.Storage.Streams/IRandomAccessStream.cs
Outdated
Show resolved
Hide resolved
Add a C# stub enum Windows.Foundation.UniversalApiContract (with ContractVersion attribute) required for ABI projection of value types and delegates; marshalling of this type is not supported. Also add a mapping entry in src/cswinrt/helpers.h so the contract is recognized during codegen.
Introduce Windows.Storage.Streams.IBuffer (new IBuffer.cs) with GUID, ContractVersion and Capacity/Length members for WinRT interop. Update src/cswinrt/helpers.h to register the IBuffer type mapping and tidy up trailing commas in the type mapping tables to allow additional entries.
Introduce ABI/COM interop support for Windows.Storage.Streams.IBuffer. Adds a new IBuffer marshaller, IBufferMethods wrappers, the IBufferVftbl layout, and a managed IBufferImpl providing UnmanagedCallersOnly stubs for get_Capacity/get_Length/set_Length with HRESULT/RestrictedErrorInfo handling. Also includes a DynamicInterfaceCastable implementation (IBufferInterfaceImpl) and assembly TypeMap/TypeMapAssociation entries for runtime type mapping.
Add support for Windows.Storage.Streams.IBuffer across the generator and runtime. This adds an IBuffer TypeReference in InteropReferences, includes IBuffer in WindowsRuntimeExtensions runtime-type checks, and emits the IID mapping in WellKnownInterfaceIIDs (and its template entries) so IBuffer is recognized and usable for WinRT interop.
Introduce Windows.Storage.Streams.InputStreamOptions enum to WinRT.Runtime2 to mirror the UWP API. The enum is annotated with Windows Runtime metadata (WindowsRuntimeMetadata, WindowsRuntimeClassName, WindowsRuntimeReferenceType), SupportedOSPlatform and ContractVersion attributes, and marked with Flags. Defines three values: None (0), Partial (1) and ReadAhead (2).
Introduce ABI marshalling for Windows.Storage.Streams.InputStreamOptions: add InputStreamOptions.cs implementing boxing/unboxing, interface entries, and a WindowsRuntimeComWrappers marshaller attribute to support COM interop. Also add the IReferenceOfInputStreamOptions IID to WellKnownWindowsInterfaceIIDs.g.cs and update the WellKnownWindowsInterfaceIIDs.tt template to include the new IID entry.
Add support for Windows.Storage.Streams.InputStreamOptions in the interop generator: introduce an InputStreamOptions TypeReference in InteropReferences, register the mapping in cswinrt/helpers.h, and treat InputStreamOptions as a known WinRT type in WindowsRuntimeExtensions so the generator recognizes and handles it like other built-in WinRT types.
Add a new IInputStream definition under Windows.Storage.Streams in WinRT.Runtime2. The interface includes licensing header, WinRT metadata attributes (WindowsRuntimeMetadata, Guid, ContractVersion), implements IDisposable, and declares the ReadAsync method returning IAsyncOperationWithProgress<IBuffer, uint> with XML docs and remarks describing buffer semantics and usage guidance.
Add the ABI.Windows.Storage.Streams.InputStreamOptionsComWrappersMarshaller attribute to the InputStreamOptions enum in src/WinRT.Runtime2/Windows.Storage.Streams/InputStreamOptions.cs to enable custom ComWrappers-based marshalling for this enum.
Introduce ABI support for Windows.Storage.Streams.IInputStream by adding a new IInputStream.cs containing marshalling helpers, vtable layout, managed->unmanaged and unmanaged->managed call paths, and a DynamicInterfaceCastable implementation. Also add the IInputStream IID to WellKnownWindowsInterfaceIIDs.g.cs and update the IID template (WellKnownWindowsInterfaceIIDs.tt) to include the new entry so the IID can be generated.
Introduce Windows.Storage.Streams.IOutputStream in src/WinRT.Runtime2/Windows.Storage.Streams/IOutputStream.cs. The new interface (inherits IDisposable) models a sequential byte output stream and exposes WriteAsync(IBuffer) returning IAsyncOperationWithProgress<uint,uint> and FlushAsync() returning IAsyncOperation<bool>. Includes WinRT metadata attributes (Guid, ContractVersion) and XML documentation describing behavior and usage.
Add ABI marshalling and runtime support for Windows.Storage.Streams.IOutputStream. Introduces a new IOutputStream.cs that provides the marshaller, unmanaged vtable (IOutputStreamVftbl), managed-to-unmanaged implementations for WriteAsync and FlushAsync, a DynamicInterfaceCastable implementation, and type mappings. Also add the IOutputStream IID to WellKnownWindowsInterfaceIIDs.g.cs and include the entry in the WellKnownWindowsInterfaceIIDs.tt template. This enables proper COM/WinRT interop for IOutputStream (905A0FE6-BC53-11DF-8C49-001E4FC686DA) and error/ownership handling for async operations.
Register Windows.Storage.Streams.IInputStream and IOutputStream across the generator: add TypeReference properties in InteropReferences, add entries to the cswinrt helpers mapping, and update WindowsRuntimeExtensions to recognize these interfaces alongside IBuffer. This ensures the generator correctly identifies and references WinRT input/output stream types.
Introduce Windows.Storage.Streams.IRandomAccessStream to WinRT.Runtime2. The new interface (with WinRT metadata, GUID, and contract version attributes) extends IDisposable, IInputStream, and IOutputStream and exposes CanRead, CanWrite, Position, Size, GetInputStreamAt, GetOutputStreamAt, Seek, and CloneStream. File includes copyright/mit header and XML documentation.
Introduce full interop support for Windows.Storage.Streams.IRandomAccessStream: add ABI/IRandomAccessStream.cs containing marshaller, unmanaged vtable (IRandomAccessStreamVftbl), managed-to-unmanaged implementations (IRandomAccessStreamImpl), interface castable proxy, and helper methods for calling the COM methods. Also register type maps/associations for the interface. Update WellKnownWindowsInterfaceIIDs.g.cs and its template (.tt) to include the IRandomAccessStream IID (905A0FE1-BC53-11DF-8C49-001E4FC686DA) so the new marshalling code can reference the correct GUID. This enables proper runtime interop for random-access stream operations.
Add support for Windows.Storage.Streams.IRandomAccessStream across the generator and helpers: register IRandomAccessStream in cswinrt/helpers.h, add an IRandomAccessStream TypeReference in InteropReferences, and include it in WindowsRuntimeExtensions.IsStream checks so it is recognized as a stream type.
Replace incorrect/common GUID used for DynamicInterfaceCastableImplementation with the correct WinRT interface IDs for several Storage.Streams types. Updated IBuffer, IInputStream, IOutputStream, and IRandomAccessStream implementations to use their proper GUIDs to ensure correct runtime casting/interop. Changes: - IBuffer: 00000036-0000-0000-C000-000000000046 -> 905A0FE0-BC53-11DF-8C49-001E4FC686DA - IRandomAccessStream: 00000036-0000-0000-C000-000000000046 -> 905A0FE1-BC53-11DF-8C49-001E4FC686DA - IInputStream: 00000036-0000-0000-C000-000000000046 -> 905A0FE2-BC53-11DF-8C49-001E4FC686DA - IOutputStream: 00000036-0000-0000-C000-000000000046 -> 905A0FE6-BC53-11DF-8C49-001E4FC686DA This fixes interface identity mismatches that could break dynamic casting or ABI interop.
Remove redundant null-forgiving ('!') operators from enumerator and collection code where runtime checks already guarantee non-null values. Cleans up nullable handling and improves code clarity across several files:
- src/WinRT.Runtime2/Bindables/WindowsRuntimeEnumerator.cs
- src/WinRT.Runtime2/Collections/WindowsRuntimeEnumerator{T}.cs
- src/WinRT.Runtime2/Collections/DictionaryKeyCollection{TKey, TValue}.cs
- src/WinRT.Runtime2/Collections/DictionaryValueCollection{TKey, TValue}.cs
- src/WinRT.Runtime2/Collections/ReadOnlyDictionaryKeyCollection{TKey, TValue}.cs
- src/WinRT.Runtime2/Collections/ReadOnlyDictionaryValueCollection{TKey, TValue}.cs
- src/WinRT.Runtime2/InteropServices/Collections/IReadOnlyDictionarySplitAdapter{TKey, TValue}.cs
Add CS9264 to the #pragma warning disable list in WindowsRuntimeEnumerator{T}.cs so the CS9264 compiler warning is suppressed alongside the existing CA1816 and IDE0046 disables.
Replace placeholder IID for IReferenceOfInputStreamOptions with the correct GUID (AEA3CA95-06D3-5B19-A94D-907D1E6BCF18). Update the generated byte array in WellKnownWindowsInterfaceIIDs.g.cs and the source template WellKnownWindowsInterfaceIIDs.tt (remove TODO). This ensures the runtime exposes the correct interface identifier.
f346a13 to
53fbaa3
Compare
Add IID mappings for Windows.Storage.Streams interfaces. Updated the generator references to recognize IBuffer, IInputStream, IOutputStream and IRandomAccessStream; added corresponding ref readonly Guid properties in WellKnownInterfaceIIDs.g.cs that delegate to WellKnownWindowsInterfaceIIDs; and updated the WellKnownInterfaceIIDs.tt template to include the new entries. This enables correct projection/mapping of storage stream interfaces.
Replace the IID reference for IBuffer in WindowsRuntimeBuffer static initialization to use WindowsRuntime.InteropServices.WellKnownInterfaceIIDs instead of ABI.InterfaceIIDs. This unifies the IID source with the WellKnownInterfaceIIDs set and aligns the code with other interface IID usages.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR makes the following types manually-projected:
IBufferIInputStreamIOutputStreamIRandomAccessStreamInputStreamOptions