Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b7d7d90
Add IAsyncActionWithProgressVftbl struct
Sergio0694 Sep 27, 2025
808e897
Add IAsyncActionWithProgressMethods utility class
Sergio0694 Sep 27, 2025
52e83de
Add IAsyncActionWithProgressMethodsImpl interface
Sergio0694 Sep 27, 2025
a73a2ae
Add WindowsRuntimeAsyncActionWithProgress implementation
Sergio0694 Sep 27, 2025
d42e851
Add IAsyncOperationVftbl struct for WinRT interop
Sergio0694 Sep 27, 2025
7ea13dc
Add IAsyncOperationMethodsImpl interface
Sergio0694 Sep 27, 2025
796d2a9
Add WindowsRuntimeAsyncOperation implementation
Sergio0694 Sep 27, 2025
8e5d74f
Add IAsyncOperationWithProgress vtable struct
Sergio0694 Sep 27, 2025
ac30f37
Add IAsyncOperationWithProgressMethodsImpl interface
Sergio0694 Sep 27, 2025
8377a30
Add WindowsRuntimeAsyncOperationWithProgress implementation
Sergio0694 Sep 27, 2025
9428292
Add NoInlining to GetResults method
Sergio0694 Sep 27, 2025
1830c7b
Remove unused IAsyncOperation vtable structs
Sergio0694 Oct 3, 2025
4075cac
Add IAsyncOperationVftbl type definition and registration
Sergio0694 Oct 3, 2025
fba750b
Add support for IAsyncOperation<TResult> interop types
Sergio0694 Oct 3, 2025
45255f5
Add IAsyncOperation1 IID helper and integrate in generator
Sergio0694 Oct 3, 2025
40821ec
Mark internal members as obsolete and update interface IDs
Sergio0694 Oct 24, 2025
9eeb6e1
Implement IWindowsRuntimeInterface<IAsyncInfo> support
Sergio0694 Oct 24, 2025
fd9a58b
Remove 'IID' suffix from type name in IAsyncOperation1
Sergio0694 Oct 24, 2025
159ad37
Fix vtable layout comment for IAsyncOperation
Sergio0694 Oct 24, 2025
13db9f9
Add handler and untyped return value signatures
Sergio0694 Oct 24, 2025
d4b36a5
Refactor method signature creation for async operations
Sergio0694 Oct 24, 2025
0e61ecd
Add IAsyncActionWithProgressVftbl type definition
Sergio0694 Oct 24, 2025
17d0250
Add IAsyncOperationWithProgress vtable support
Sergio0694 Oct 24, 2025
1d4721f
Add IAsyncOperation1 methods and references
Sergio0694 Oct 24, 2025
cc7e614
Add NativeObject builder for IAsyncOperation1
Sergio0694 Oct 24, 2025
0dc401d
Add ComWrappersCallbackType for IAsyncOperation1
Sergio0694 Oct 24, 2025
50633cd
Add ComWrappersMarshallerAttribute for IAsyncOperation1
Sergio0694 Oct 24, 2025
f478fd6
Add Marshaller method for IAsyncOperation1
Sergio0694 Oct 24, 2025
c5b9d94
Add IAsyncOperation1 interface implementation builder
Sergio0694 Oct 24, 2025
ce74e71
Add proxy type generation for IAsyncOperation1
Sergio0694 Oct 24, 2025
b8f05d4
Add TypeMapAttributes for IAsyncOperation1
Sergio0694 Oct 24, 2025
88125e1
Add ImplType builder for IAsyncOperation1
Sergio0694 Oct 24, 2025
0f5ffb7
Add IAsyncInfo handler method factory
Sergio0694 Oct 24, 2025
be3861a
Refactor Completed method creation for IAsyncOperation
Sergio0694 Oct 24, 2025
94e0b5c
Add set method for IAsyncOperation Completed handler
Sergio0694 Oct 24, 2025
f4f69ad
Add GetResults method support for IAsyncOperation
Sergio0694 Oct 24, 2025
4f89a1f
Add get_Completed handler for IAsyncOperation<T>
Sergio0694 Oct 24, 2025
52c3697
Add set_Completed method for IAsyncOperation<T>
Sergio0694 Oct 24, 2025
1469ef5
Add support for IAsyncActionWithProgress<TProgress> types
Sergio0694 Oct 24, 2025
3034ee3
Add IAsyncActionWithProgress1 IID helper and use in Emit
Sergio0694 Oct 24, 2025
af19172
Add interop support for IAsyncActionWithProgress<T>
Sergio0694 Oct 24, 2025
f68a2b2
Handle additional async handler types in marshaller logic
Sergio0694 Oct 24, 2025
0119f47
Add GetResults method for IAsyncActionWithProgress
Sergio0694 Oct 24, 2025
71fb585
Add NativeObject support for IAsyncActionWithProgress<T>
Sergio0694 Oct 24, 2025
b3ce6ef
Add ComWrappersCallbackType for IAsyncActionWithProgress
Sergio0694 Oct 24, 2025
d525455
Add marshaller attribute generation for IAsyncActionWithProgress
Sergio0694 Oct 24, 2025
01a542b
Add Marshaller method for IAsyncActionWithProgress1
Sergio0694 Oct 24, 2025
1cd93e9
Add interface implementation for IAsyncActionWithProgress<T>
Sergio0694 Oct 24, 2025
11b40f2
Add proxy type generation for IAsyncActionWithProgress<T>
Sergio0694 Oct 24, 2025
cfb579f
Add TypeMapAttributes for IAsyncActionWithProgress<T>
Sergio0694 Oct 24, 2025
bdd7dd4
Add ImplType for IAsyncActionWithProgress<TProgress>
Sergio0694 Oct 24, 2025
744c415
Implement GetResults for IAsyncActionWithProgress1
Sergio0694 Oct 24, 2025
bc73365
Mark internal async classes as obsolete and hide from editor
Sergio0694 Oct 25, 2025
e18cfbb
Remove redundant <remarks> from internal collection types
Sergio0694 Oct 25, 2025
9ad457c
Add support for IAsyncOperationWithProgress types
Sergio0694 Oct 25, 2025
2aec01a
Track delegate types for async interface instantiations
Sergio0694 Oct 25, 2025
975bb2c
Add IAsyncOperationWithProgress2 IID helper and usage
Sergio0694 Oct 25, 2025
8c1753b
Add IAsyncOperationWithProgress2 methods and references
Sergio0694 Oct 25, 2025
1436ffe
Add NativeObject support for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
4181117
Add ComWrappersCallbackType for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
75a08e0
Add marshaller attribute generation for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
5760d4d
Add Marshaller method for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
de1f144
Add interface implementation for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
6c3ced4
Add proxy type generation for IAsyncOperationWithProgress
Sergio0694 Oct 25, 2025
545a5c3
Add TypeMapAttributes for IAsyncOperationWithProgress
Sergio0694 Oct 25, 2025
c538350
Add ImplType method for IAsyncOperationWithProgress2
Sergio0694 Oct 25, 2025
46de41c
Handle additional async handler types in marshaller tracking
Sergio0694 Oct 25, 2025
3c5533d
Suppress warnings in IAsyncInfoMethods factory
Sergio0694 Oct 26, 2025
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/WinRT.Interop.Generator/Errors/WellKnownInteropExceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,30 @@ public static Exception DynamicImplementationDetailTypeCodeGenerationError(Excep
return Exception(43, $"Failed to generate marshalling code for some dynamic implementation detail type.", exception);
}

/// <summary>
/// Failed to generate marshalling code for an <c>Windows.Foundation.IAsyncActionWithProgress&lt;TProgress&gt;</c> type.
/// </summary>
public static Exception IAsyncActionWithProgressTypeCodeGenerationError(TypeSignature actionType, Exception exception)
{
return Exception(44, $"Failed to generate marshalling code for 'IAsyncActionWithProgress<TResult>' type '{actionType}'.", exception);
}

/// <summary>
/// Failed to generate marshalling code for an <c>Windows.Foundation.IAsyncOperation&lt;TResult&gt;</c> type.
/// </summary>
public static Exception IAsyncOperationTypeCodeGenerationError(TypeSignature operationType, Exception exception)
{
return Exception(45, $"Failed to generate marshalling code for 'IAsyncOperation<TResult>' type '{operationType}'.", exception);
}

/// <summary>
/// Failed to generate marshalling code for an <c>Windows.Foundation.IAsyncOperationWithProgress&lt;TResult, TProgress&gt;</c> type.
/// </summary>
public static Exception IAsyncOperationWithProgressTypeCodeGenerationError(TypeSignature operationType, Exception exception)
{
return Exception(46, $"Failed to generate marshalling code for 'IAsyncOperationWithProgress<TResult, TProgress>' type '{operationType}'.", exception);
}

/// <summary>
/// Creates a new exception with the specified id and message.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void TrackGenericInterfaceType(
// type. This ensures that we're never missing any 'IEnumerator<T>' instantiation, which we might depend on
// from other generated code, or projections. This special handling is needed because unlike with the other
// interfaces, 'IEnumerator<T>' will not show up as a base interface for other collection interface types.
discoveryState.TrackIEnumerator1Type(interopReferences.IEnumerator1.MakeGenericReferenceType(typeSignature.TypeArguments[0]));
discoveryState.TrackIEnumerator1Type(interopReferences.IEnumerator1.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IList1))
{
Expand Down Expand Up @@ -68,12 +68,34 @@ public static void TrackGenericInterfaceType(
{
discoveryState.TrackIObservableMap2Type(typeSignature);

// Same handling as below for 'MapChangedEventHandler<K,V>' types
// Same handling as above for 'MapChangedEventHandler<K,V>' types
discoveryState.TrackGenericDelegateType(interopReferences.MapChangedEventHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IMapChangedEventArgs1))
{
discoveryState.TrackIMapChangedEventArgs1Type(typeSignature);
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncActionWithProgress1))
{
discoveryState.TrackIAsyncActionWithProgress1Type(typeSignature);

// Ensure that the delegate types for this instantiation of 'IAsyncActionWithProgress<TProgress>' are also tracked.
// Same rationale as above for the other special cased types. Same below as well for the other async info types.
discoveryState.TrackGenericDelegateType(interopReferences.AsyncActionProgressHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
discoveryState.TrackGenericDelegateType(interopReferences.AsyncActionWithProgressCompletedHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncOperation1))
{
discoveryState.TrackIAsyncOperation1Type(typeSignature);

discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationCompletedHandler1.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
}
else if (SignatureComparer.IgnoreVersion.Equals(typeSignature.GenericType, interopReferences.IAsyncOperationWithProgress2))
{
discoveryState.TrackIAsyncOperationWithProgress2Type(typeSignature);

discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationProgressHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
discoveryState.TrackGenericDelegateType(interopReferences.AsyncOperationWithProgressCompletedHandler2.MakeGenericReferenceType([.. typeSignature.TypeArguments]));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using AsmResolver.DotNet;
using AsmResolver.DotNet.Code.Cil;
using AsmResolver.DotNet.Signatures;
using AsmResolver.PE.DotNet.Cil;
using AsmResolver.PE.DotNet.Metadata.Tables;
using WindowsRuntime.InteropGenerator.References;
using static AsmResolver.PE.DotNet.Cil.CilOpCodes;

namespace WindowsRuntime.InteropGenerator.Factories;

/// <inheritdoc cref="InteropMethodDefinitionFactory"/>
internal partial class InteropMethodDefinitionFactory
{
/// <summary>
/// Helpers for impl types for <c>Windows.Foundation.IAsyncActionWithProgress&lt;TProgress&gt;</c> interfaces.
/// </summary>
public static class IAsyncActionWithProgress1Impl
{
/// <summary>
/// Creates a <see cref="MethodDefinition"/> for the <c>GetResults</c> export method.
/// </summary>
/// <param name="actionType">The <see cref="TypeSignature"/> for the async action type.</param>
/// <param name="interopReferences">The <see cref="InteropReferences"/> instance to use.</param>
/// <param name="module">The interop module being built.</param>
public static MethodDefinition GetResults(
GenericInstanceTypeSignature actionType,
InteropReferences interopReferences,
ModuleDefinition module)
{
TypeSignature progressType = actionType.TypeArguments[0];

// Define the 'GetResults' method as follows:
//
// [UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])]
// private static int GetResults(void* thisPtr)
MethodDefinition getResultsMethod = new(
name: "GetResults"u8,
attributes: MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static,
signature: MethodSignature.CreateStatic(
returnType: module.CorLibTypeFactory.Int32,
parameterTypes: [module.CorLibTypeFactory.Void.MakePointerType()]))
{
CustomAttributes = { InteropCustomAttributeFactory.UnmanagedCallersOnly(interopReferences, module) }
};

// Labels for jumps
CilInstruction ldarg_0_tryStart = new(Ldarg_0);
CilInstruction ldloc_0_returnHResult = new(Ldloc_0);
CilInstruction call_catchStartMarshalException = new(Call, interopReferences.RestrictedErrorInfoExceptionMarshallerConvertToUnmanaged.Import(module));

// Declare the local variables:
// [0]: 'int' (the 'HRESULT' to return)
CilLocalVariable loc_0_hresult = new(module.CorLibTypeFactory.Int32);

// Create a method body for the 'get_Current' method
getResultsMethod.CilMethodBody = new CilMethodBody()
{
LocalVariables = { loc_0_hresult },
Instructions =
{
// '.try' code
{ ldarg_0_tryStart },
{ Call, interopReferences.ComInterfaceDispatchGetInstance.MakeGenericInstanceMethod(actionType).Import(module) },
{ Callvirt, interopReferences.IAsyncActionWithProgress1GetResults(progressType).Import(module) },
{ Ldc_I4_0 },
{ Stloc_0 },
{ Leave_S, ldloc_0_returnHResult.CreateLabel() },

// '.catch' code
{ call_catchStartMarshalException },
{ Stloc_0 },
{ Leave_S, ldloc_0_returnHResult.CreateLabel() },

// Return the 'HRESULT' from location [0]
{ ldloc_0_returnHResult },
{ Ret }
},
ExceptionHandlers =
{
new CilExceptionHandler
{
HandlerType = CilExceptionHandlerType.Exception,
TryStart = ldarg_0_tryStart.CreateLabel(),
TryEnd = call_catchStartMarshalException.CreateLabel(),
HandlerStart = call_catchStartMarshalException.CreateLabel(),
HandlerEnd = ldloc_0_returnHResult.CreateLabel(),
ExceptionType = interopReferences.Exception.Import(module)
}
}
};

return getResultsMethod;
}
}
}
Loading
Loading