Skip to content
Open
Show file tree
Hide file tree
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 Feb 12, 2026
386c656
Add IBuffer interface and register mapping
Sergio0694 Feb 12, 2026
aae7583
Add ABI marshalling for IBuffer
Sergio0694 Feb 12, 2026
651fe4f
Add IBuffer interop references and IID
Sergio0694 Feb 12, 2026
0c6cbd8
Add InputStreamOptions enum for WinRT runtime
Sergio0694 Feb 13, 2026
f7bf1f2
Add InputStreamOptions marshaller and IID
Sergio0694 Feb 13, 2026
4d39079
Add InputStreamOptions to interop references
Sergio0694 Feb 13, 2026
c2cb53f
Add IInputStream interface for WinRT streams
Sergio0694 Feb 13, 2026
4552952
Add ComWrappers marshaller to InputStreamOptions
Sergio0694 Feb 13, 2026
2298df0
Add IInputStream ABI marshaller and IID
Sergio0694 Feb 13, 2026
3b5bf5c
Add IOutputStream interface
Sergio0694 Feb 13, 2026
760fbbc
Add IOutputStream marshaller and IID
Sergio0694 Feb 13, 2026
03d1548
Add IInputStream and IOutputStream WinRT refs
Sergio0694 Feb 13, 2026
bd09477
Add IRandomAccessStream interface
Sergio0694 Feb 13, 2026
349f618
Add IRandomAccessStream marshalling and IID
Sergio0694 Feb 13, 2026
9b05aaa
Add IRandomAccessStream support
Sergio0694 Feb 13, 2026
5ce2da4
Update GUIDs for Windows.Storage.Streams interfaces
Sergio0694 Feb 13, 2026
6df8974
Remove unnecessary null-forgiving operators
Sergio0694 Feb 13, 2026
885b6ca
Suppress CS9264 in WindowsRuntimeEnumerator
Sergio0694 Feb 13, 2026
ca0a0ee
Fix IID for IReferenceOfInputStreamOptions
Sergio0694 Feb 13, 2026
53fbaa3
Fix typo
Sergio0694 Feb 13, 2026
badfd58
Add Storage.Streams interface IIDs
Sergio0694 Feb 13, 2026
130ee69
Use WellKnownInterfaceIIDs for IBuffer IID
Sergio0694 Feb 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions src/WinRT.Interop.Generator/References/InteropReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,31 @@ public InteropReferences(
/// </summary>
public TypeReference AsyncOperationWithProgressCompletedHandler2 => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Foundation"u8, "AsyncOperationWithProgressCompletedHandler`2"u8);

/// <summary>
/// Gets the <see cref="AsmResolver.DotNet.TypeReference"/> for <c>Windows.Storage.Streams.IBuffer</c>.
/// </summary>
public TypeReference IBuffer => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IBuffer"u8);

/// <summary>
/// Gets the <see cref="AsmResolver.DotNet.TypeReference"/> for <c>Windows.Storage.Streams.IInputStream</c>.
/// </summary>
public TypeReference IInputStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IInputStream"u8);

/// <summary>
/// Gets the <see cref="AsmResolver.DotNet.TypeReference"/> for <c>Windows.Storage.Streams.IOutputStream</c>.
/// </summary>
public TypeReference IOutputStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IOutputStream"u8);

/// <summary>
/// Gets the <see cref="AsmResolver.DotNet.TypeReference"/> for <c>Windows.Storage.Streams.IRandomAccessStream</c>.
/// </summary>
public TypeReference IRandomAccessStream => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "IRandomAccessStream"u8);

/// <summary>
/// Gets the <see cref="AsmResolver.DotNet.TypeReference"/> for <c>Windows.Storage.Streams.InputStreamOptions</c>.
/// </summary>
public TypeReference InputStreamOptions => field ??= _windowsRuntimeModule.CreateTypeReference("Windows.Storage.Streams"u8, "InputStreamOptions"u8);

/// <summary>
/// Gets the <see cref="MemberReference"/> for <see cref="string.Length"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
259 changes: 259 additions & 0 deletions src/WinRT.Runtime2/ABI/Windows.Storage.Streams/IBuffer.cs
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);

return IBufferMethods.Length(thisReference);
}
set
{
var thisReference = ((WindowsRuntimeObject)this).GetObjectReferenceForInterface(typeof(IBuffer).TypeHandle);

IBufferMethods.Length(thisReference, value);
}
}
}
Loading
Loading