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

Add DataTransferManger interop APIs #1528

Merged
merged 9 commits into from
Mar 14, 2024
8 changes: 8 additions & 0 deletions src/Tests/UnitTest/ComInteropTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.DataTransfer.DragDrop.Core;
using Windows.Graphics.Display;
using Windows.Graphics.Printing;
Expand Down Expand Up @@ -161,5 +162,12 @@ public void TestDisplayInformation()
Assert.Throws<COMException>(() => DisplayInformationInterop.GetForWindow(new IntPtr(0)));
Assert.Throws<COMException>(() => DisplayInformationInterop.GetForMonitor(new IntPtr(0)));
}

[Fact]
public void TestDataTransferManager()
{
Assert.Throws<COMException>(() => DataTransferManagerInterop.GetForWindow(new IntPtr(0)));
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
DataTransferManagerInterop.ShowShareUIForWindow(new IntPtr(0));
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
64 changes: 64 additions & 0 deletions src/cswinrt/strings/ComInteropHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,67 @@ public static DisplayInformation GetForMonitor(IntPtr monitor)
}
#endif
}

namespace Windows.ApplicationModel.DataTransfer
{
#if UAC_VERSION_1
#if NET
[global::System.Runtime.Versioning.SupportedOSPlatform("Windows10.0.10240.0")]
#endif
#if EMBED
internal
#else
public
#endif
static class DataTransferManagerInterop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to add XML docs.

{
private static readonly global::System.Guid riid = new global::System.Guid(0xA5CAEE9B, 0x8708, 0x49D1, 0x8D, 0x36, 0x67, 0xD2, 0x5A, 0x8D, 0xA0, 0x0C);

#if NET
private static global::WinRT.IObjectReference objectReference = global::WinRT.ActivationFactory.Get("Windows.ApplicationModel.DataTransfer.DataTransferManager", new global::System.Guid(0x3A3DCD6C, 0x3EAB, 0x43DC, 0xBC, 0xDE, 0x45, 0x67, 0x1C, 0xE8, 0x00, 0xC8));
#else
private static global::WinRT.ObjectReference<global::WinRT.Interop.IUnknownVftbl> objectReference = global::WinRT.ActivationFactory.Get<global::WinRT.Interop.IUnknownVftbl>("Windows.ApplicationModel.DataTransfer.DataTransferManager", new global::System.Guid(0x3A3DCD6C, 0x3EAB, 0x43DC, 0xBC, 0xDE, 0x45, 0x67, 0x1C, 0xE8, 0x00, 0xC8));
#endif

public static global::Windows.ApplicationModel.DataTransfer.DataTransferManager GetForWindow(global::System.IntPtr appWindow)
{
return IDataTransferManagerInteropMethods.GetForWindow(objectReference, appWindow, riid);
}

public static void ShowShareUIForWindow(global::System.IntPtr appWindow)
{
IDataTransferManagerInteropMethods.ShowShowShareUIForWindow(objectReference, appWindow);
}
}
#endif

internal static class IDataTransferManagerInteropMethods
{
internal static unsafe global::Windows.ApplicationModel.DataTransfer.DataTransferManager GetForWindow(global::WinRT.IObjectReference _obj, global::System.IntPtr appWindow, in global::System.Guid riid)
manodasanW marked this conversation as resolved.
Show resolved Hide resolved
{
global::System.IntPtr thisPtr = _obj.ThisPtr;
global::System.IntPtr ptr = default;


try
{
// IDataTransferManagerInterop inherits IUnknown (3 functions) and provides GetForWindow giving a total of 5 functions
fixed(Guid* _riid = &riid)
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<global::System.IntPtr, global::System.IntPtr, global::System.Guid*, global::System.IntPtr*, int>**)thisPtr)[3](thisPtr, appWindow, _riid, &ptr));
return global::WinRT.MarshalInspectable<global::Windows.ApplicationModel.DataTransfer.DataTransferManager>.FromAbi(ptr);
}
finally
{
global::WinRT.MarshalInspectable<DataTransferManager>.DisposeAbi(ptr);
}
}

internal static unsafe void ShowShowShareUIForWindow(global::WinRT.IObjectReference _obj, global::System.IntPtr appWindow)
{
global::System.IntPtr thisPtr = _obj.ThisPtr;

// IDataTransferManagerInterop inherits IUnknown (3 functions) and provides ShowShowShareUIForWindow giving a total of 5 functions
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<global::System.IntPtr, global::System.IntPtr, int>**)thisPtr)[4](thisPtr, appWindow));
}
}
}
manodasanW marked this conversation as resolved.
Show resolved Hide resolved