-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: ComWrappers
API to only check for an existing RCW
#113581
Comments
ComWrappers
ComWrappers
API to only check for an existing RCW
Tagging subscribers to this area: @dotnet/interop-contrib |
You can have multiple different ComWrappers instances wrapping the same external IUnknown. I think this needs to be instance method so that you know which one to use. |
It doesn't need to be. The proposed API passes in a target |
Chatted offline with Aaron, leaving context here as well as requested 🙂
To clarify, this is not actually the API we'd like for CsWinRT, and we would not be using it. We'd like to get #113591, as that'd address all our issues/requirements. I see that version mentioned in the alternative design here as well, but I've opened a separate proposal to track that just for clarity, since it's a different API shape than |
Ah ok, I have missed that. It is a topic for API review discussion. I think it is very atypical to have a method that operates on an instance state and that takes the logical Wrt. discoverability: It depends on where you start. If you are at |
Agree.
I don't know the BCL that well. Something to ask them.
I don't disagree on that opinion. I'm doing this more for consistent location of APIs by utility. If someone has a CCW and wants to unwrap it there is a static function. If someone has an RCW and wants to to see if it has a wrapper I would assume it would be close to the similar non-creating function or CCWs. It is the symmetry for the entire |
I have serious concerns with the |
I've clarified them in the other proposal. I think those concerns (which are completely fair) were only due to the name I included in the proposal. But I did mention the exact name/signature can be whatever is best and whatever API review prefers. The proposal is simply to have a |
Closing this issue as it is no longer desired. |
Background and motivation
A current API exists for taking in an
IntPtr
to anIUnknown
and checking if it is a CCW (COM Callable Wrapper). Adding a symmetrical API for checking if there is an existing wrapper for an RCW (Runtime Callable Wrapper) is also potentially interesting since it could be the case that users may want to perform a non-exception throwing check prior to callingComWrappers.GetOrRegisterObjectForComInstance()
orComWrappers.GetOrCreateObjectForComInstance()
.API Proposal
The proposal here is to reuse the
TryGetObject()
pattern, but for a nativeIUnknown
as opposed to check if theIUnknown
is an existing CCW (wrapper of a managed object).namespace System.Runtime.InteropServices; public abstract class ComWrappers { + public static bool TryGetObject(IntPtr externalComObject, ComWrappers comWrappers, out object? wrapper); }
API Usage
Alternative Designs
Convert to instance method
Follow the existing pattern and create a "Try" version
Risks
This is for a niche WinRT scenario. It has no other obvious uses at present. It does however create a symmetrical API for both CCWs and RCWs.
The API has a trivial implementation, but does introduce an inherent race condition around what is in essence a concurrent dictionary (RCW cache). The "try" operation is checking for state that might be addressed by another thread calling the
GetOrCreateObjectForComInstance
orGetOrRegisterObjectForComInstance
. This can be mitigated if the user'sComWrappers
implementation ensures that it would always create a wrapper for anIUnknown
instance based solely on the state of thatIUnknown
, but that is a hard requirement to enforce.The text was updated successfully, but these errors were encountered: