Update docs for generated interop code#2311
Open
Sergio0694 wants to merge 3 commits intostaging/3.0from
Open
Conversation
Rename and clarify marshalling APIs and generics in documentation: - Arrays: rename WindowsRuntimeArrayMarshaller.ConvertToManaged to UnboxToManaged and update marshaller attribute CreateObject to include CreatedWrapperFlags. - Generic interfaces: make WindowsRuntimeEnumerator generic on a methods implementation type (TIIteratorMethods) and expose HasUnwrappableNativeObjectReference; split type-specific Current into IIteratorMethodsImpl<T> and keep non-generic IIteratorMethods for shared methods. - Rename and extend unsealed object callback API to IWindowsRuntimeUnsealedObjectComWrappersCallback, adding TryCreateObject/CreateObject overloads that return wrapperFlags; update WindowsRuntimeUnsealedObjectMarshaller callback constraint. - RCW/WinRT.Interop changes: generate IIterator_stringMethods implementing IIteratorMethodsImpl<string>, simplify forwarding via non-generic methods types, produce native object types that use the generic base (WindowsRuntimeEnumerator<T, TIIteratorMethods>) and new ComWrappers callback signatures including wrapperFlags and wrapperObject. - CCW/adapter changes: describe a generic IEnumeratorAdapter<T> in the runtime with a ConditionalWeakTable-backed GetInstance, and update CCW vtable patterns to obtain adapters for semantics adjustments. - Misc: update marshaller use to WindowsRuntimeInterfaceMarshaller<T> and various explanatory clarifications throughout the documents.
Replace WindowsRuntimeObjectReference.AsUnsafe with the updated CreateUnsafe API and implement actual marshalling for IEnumerator<T>.Current by calling HStringMarshaller.ConvertToUnmanaged instead of the placeholder. This updates the marshaller to use the new unsafe constructor and provides concrete HSTRING conversion for string enumeration interop.
Update marshalling example to use WindowsRuntimeObjectReference.Create instead of CreateUnsafe and remove the unused ComputeVtables stub. Expand the accompanying explanation to clarify that Create performs a QueryInterface on an opaque IInspectable pointer (required here), while CreateUnsafe assumes the pointer already targets the requested interface and only increments the ref count — which is safe for the ComWrappers TryCreateObject fast path.
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 pull request updates the documentation for CsWinRT generic interface marshalling, refines the design for runtime callable wrappers (RCWs) and COM callable wrappers (CCWs), and clarifies the separation of type-specific and shared logic for generic interface marshalling. The changes introduce new marshaller interfaces and attributes, update method signatures for improved clarity and correctness, and shift the implementation strategy to use shared runtime adapter types rather than generating per-type adapters.
RCW marshalling and generic interface design
WindowsRuntimeEnumerator<T, TIIteratorMethods>, which is now generic over both the element type and a type-specific static interface for marshalling theCurrentmethod. The base class handles allIEnumerator<T>state management and semantics adaptation.IIteratorMethodsImpl<T>for type-specific marshalling (onlyCurrent), and a shared static classIIteratorMethodsfor non-type-specific methods (HasCurrent,MoveNext).IEnumerator_stringNativeObject) to use the new generic base class and rely on the shared runtime logic, removing the need to override abstract methods.Marshaller interfaces and attributes
IWindowsRuntimeUnsealedComWrappersCallback→IWindowsRuntimeUnsealedObjectComWrappersCallback, and updated method signatures to returnCreatedWrapperFlagsfor additional wrapper metadata. [1] [2] [3]CCW marshalling and runtime adapter strategy
IEnumeratorAdapter<T>defined inWinRT.Runtime.dll, replacing the previous strategy of generating per-type adapters and tables. This adapter provides correct semantics adaptation and efficient instance management via a sharedConditionalWeakTable.Vtable and method signature corrections
get_Currentto useHSTRING*for string marshalling and updated the implementation to use the shared runtime adapter and marshaller.These changes clarify the separation of type-specific and shared logic, improve marshalling correctness, and simplify the code generation and runtime infrastructure for generic interface support in CsWinRT.