Skip to content
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

Need to handle incoming IDataObject pointers for AOT #9805

Closed
Tracked by #10624 ...
JeremyKuhne opened this issue Aug 29, 2023 · 2 comments
Closed
Tracked by #10624 ...

Need to handle incoming IDataObject pointers for AOT #9805

JeremyKuhne opened this issue Aug 29, 2023 · 2 comments

Comments

@JeremyKuhne
Copy link
Member

In order to support trimming/AOT we'll be moving our OLE interactions to native pointers and ComWrappers. In doing that we'll need to handle incoming IDataObject pointers. This issue is to capture some of what this entails.

When we get IDataObject* from OLE (for drag/drop and clipboard) we have a number of cases:

  1. The IDataObject* is a CCW from COM interop.
  2. The IDataObject* is a CCW from ComWrappers
  3. The IDataObject* is neither (originally created in native code - that is originating outside of .NET).

In the first case we need to recognize that and unwrap the managed object if it was one that we populated. It is possible someone else may have manually P/Invoked data out and we need to be aware of it and consider if we're breaking any casting support that COM interop provides.

The second case is much the same, we want to get the original DataObject out and not try and wrap in a ComWrappers RCW.

Third case is a bit more tricky. Historically we have wrapped this in a COM interop RCW. This allows dynamic casting of any supported COM interface via QueryInterface. While we can create a ComWrappers RCW, we wouldn't get this behavior anymore in that case.

For example in CreateDragEventArgs:

object? obj = Marshal.GetObjectForIUnknown((nint)pDataObj);
if (obj is IDataObject dataObject)
{
    data = dataObject;
}
else if (obj is ComTypes.IDataObject nativeDataObject)
{
    data = new DataObject(nativeDataObject);
}

Because of this lack of dynamic casting we'll have to either use built in COM when it is available and/or allow configuring the behavior based on config switches.

@elachlan
Copy link
Contributor

Unsure if correct place, apologies if not.

Ole32.ReleaseStgMedium uses System.Runtime.InteropServices.ComTypes. So I can't convert it to CsWin32. Should ReleaseStgMedium be added to the System.Runtime.InteropServices namespace via runtime? My quick google sees quite a few people implementing their own DllImport where it would make sense to just expose it via runtime.

@elachlan
Copy link
Contributor

Also are we going to continue to use the types from System.Runtime.InteropServices.ComTypes or move to the ones generated from cswin32?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants