diff --git a/src/Tests/UnitTest/ComInteropTests.cs b/src/Tests/UnitTest/ComInteropTests.cs index e2f6c80a0..a7b6c50cc 100644 --- a/src/Tests/UnitTest/ComInteropTests.cs +++ b/src/Tests/UnitTest/ComInteropTests.cs @@ -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; @@ -161,5 +162,12 @@ public void TestDisplayInformation() Assert.Throws(() => DisplayInformationInterop.GetForWindow(new IntPtr(0))); Assert.Throws(() => DisplayInformationInterop.GetForMonitor(new IntPtr(0))); } + + [Fact] + public void TestDataTransferManager() + { + Assert.Throws(() => DataTransferManagerInterop.GetForWindow(new IntPtr(0))); + Assert.Throws(() => DataTransferManagerInterop.ShowShareUIForWindow(new IntPtr(0))); + } } } diff --git a/src/cswinrt/strings/ComInteropHelpers.cs b/src/cswinrt/strings/ComInteropHelpers.cs index 94d095d18..1895945bc 100644 --- a/src/cswinrt/strings/ComInteropHelpers.cs +++ b/src/cswinrt/strings/ComInteropHelpers.cs @@ -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 + { + 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 objectReference = global::WinRT.ActivationFactory.Get("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) + { + 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]**)thisPtr)[3](thisPtr, appWindow, _riid, &ptr)); + return global::WinRT.MarshalInspectable.FromAbi(ptr); + } + finally + { + global::WinRT.MarshalInspectable.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]**)thisPtr)[4](thisPtr, appWindow)); + } + } +}