Only Unwrap If Given IDataObject #12738
Merged
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.
Fixes #12665
In .NET 9, we had switched to leveraging cswin32 and ComWrappers for our OLE interop. During this we discovered that switching from built-in COM to ComWrappers took away the ability to automatically cast native pointers back to their original managed object when round tripping through native code. In order to remedy this, we updated to wrap the data on clipboard set and unwrap the object retrieved from the clipboard manually before returning it to get the original data.
While doing this, we had missed the fact that the native IDataObject interface doesn't have the concept of explicit autoConvert. Meaning that when calling our Clipboard APIs with autoConvert = false, it will effectively be ignored and produce same results as autoConvert = true if we're calling to a native IDataObject interface. In .NET 9, since we always unwrap the object retrieved from the clipboard to get our completely managed DataObject, we lost this behavior for types that don't already derive from managed IDataObject.
To fix this, the change here is that when we wrap types that don't already derive from the managed IDataObject, we won't automatically unwrap to the wrapping DataObject we created.
Changes also includes adding more tests to capture behavior and minor optimization with not wrapping twice
Microsoft Reviewers: Open in CodeFlow