コード例 #1
0
        /// <summary>
        /// Set binary data in the clipboard under the given format.
        /// </summary>
        public static void SetClipboardBinaryData(ReadOnlySpan <byte> span, ClipboardFormat format)
        {
            using GlobalHandle global   = Memory.Memory.GlobalAlloc((ulong)((span.Length + 1)), GlobalMemoryFlags.Moveable);
            using GlobalLock globalLock = global.Lock;
            Span <byte> buffer = globalLock.GetSpan <byte>();

            span.CopyTo(buffer);
            buffer[buffer.Length - 1] = 0;

            Imports.SetClipboardData((uint)format, globalLock.Pointer);
        }
コード例 #2
0
        /// <summary>
        /// Set Unicode text in the clipboard under the given format.
        /// </summary>
        public static void SetClipboardUnicodeText(ReadOnlySpan <char> span, ClipboardFormat format = ClipboardFormat.UnicodeText)
        {
            using GlobalHandle global   = Memory.Memory.GlobalAlloc((ulong)((span.Length + 1) * sizeof(char)), GlobalMemoryFlags.Moveable);
            using GlobalLock globalLock = global.Lock;
            Span <char> buffer = globalLock.GetSpan <char>();

            span.CopyTo(buffer);
            buffer[buffer.Length - 1] = '\0';

            Imports.SetClipboardData((uint)format, globalLock.Pointer);
        }