using System.Runtime.InteropServices; using TerraFX.Interop.Windows; using static TerraFX.Interop.Windows.Windows; namespace Dalamud.Utility; /// Clipboard formats, looked up by their names. internal static class ClipboardFormats { /// public static uint FileContents { get; } = ClipboardFormatFromName(CFSTR.CFSTR_FILECONTENTS); /// Gets the clipboard format corresponding to the PNG file format. public static uint Png { get; } = ClipboardFormatFromName("PNG"); /// public static uint FileDescriptorW { get; } = ClipboardFormatFromName(CFSTR.CFSTR_FILEDESCRIPTORW); /// public static uint FileDescriptorA { get; } = ClipboardFormatFromName(CFSTR.CFSTR_FILEDESCRIPTORA); /// public static uint FileNameW { get; } = ClipboardFormatFromName(CFSTR.CFSTR_FILENAMEW); /// public static uint FileNameA { get; } = ClipboardFormatFromName(CFSTR.CFSTR_FILENAMEA); private static unsafe uint ClipboardFormatFromName(ReadOnlySpan name) { uint cf; fixed (char* p = name) cf = RegisterClipboardFormatW(p); if (cf != 0) return cf; throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()) ?? new InvalidOperationException($"RegisterClipboardFormatW({name}) failed."); } }