`System.Runtime.InteropServices.ComTypes.IDataObject` vs `Windows.Win32.System.Com.IDataObject`
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.5k
- Forks
- 123
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 9
Description
Is your feature request related to a problem? Please describe.
Hello guys.
I'm having issue with implementing Drag&Drop in WPF for .NET 9, using IDropTargetHelper.
The problem is with DragEnter event handler.
public partial class MyWindow {
...
Windows.Win32.UI.Shell.IDropTargetHelper _dropTargetHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(PInvoke.CLSID_DragDropHelper)!) as Windows.Win32.UI.Shell.IDropTargetHelper;
...
private void MainWindow_DragEnter(object sender, DragEventArgs e)
{
...
var pointWpf = e.GetPosition(this);
var point = new System.Drawing.Point(Convert.ToInt32(pointWpf.X), Convert.ToInt32(pointWpf.Y));
_dropTargetHelper?.DragEnter(HWnd,
//here's the issue, it always results into null:
e.Data as Windows.Win32.System.Com.IDataObject,
in point, (Windows.Win32.System.Ole.DROPEFFECT)e.Effects);
}
...
Here, e.Data implements interface System.Runtime.InteropServices.ComTypes.IDataObject while Windows.Win32.UI.Shell.IDropTargetHelper expects it's own Windows.Win32.System.Com.IDataObject.
And even thought these both IDataObject are the same, there's no way to cast them, as .NET-wise, they are completely different interfaces.
And for PInvoke, CsWin32 does use System.Runtime.InteropServices.ComTypes.IDataObject.
For example, when adding SHCreateShellItemArrayFromDataObject to NativeMethods.txt, PInvoke.SHCreateShellItemArrayFromDataObject expects System.Runtime.InteropServices.ComTypes.IDataObject.
Therefore, it looks like the issue is scoped to COM interop only.
Describe the solution you'd like
When generating something that uses IDataObject, use System.Runtime.InteropServices.ComTypes.IDataObject instead.
Or provide a way to configure mapping in NativeMethods.txt, something like
CLSID_DragDropHelper
IDropTargetHelper
IDataObject=System.Runtime.InteropServices.ComTypes.IDataObject
Describe alternatives you've considered
Don't use CsWin32 in favor of plain, manually crafted COM interop.
Things like Marshal.QueryInterface/Marshal.GetComInterfaceForObject/Marshal.GetObjectForIUnknown or Unsafe.As didn't work.
Additional context
Add any other context or screenshots about the feature request here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CsWin32 generation paths for IDropTargetHelper and SHCreateShellItemArrayFromDataObject, then inspect how NativeMethods.txt declarations map IDataObject types. Reproduce the WPF DragEnter scenario and compare the generated signatures; done means the relevant generated APIs use a compatible IDataObject representation or provide the requested mapping mechanism, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- operating-systems, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100