Exemple #1
0
        public async Task <string> GetTextAsync()
        {
            await OpenClipboard();

            try
            {
                IntPtr hText = UnmanagedMethods.GetClipboardData(UnmanagedMethods.ClipboardFormat.CF_UNICODETEXT);
                if (hText == IntPtr.Zero)
                {
                    return(null);
                }

                var pText = UnmanagedMethods.GlobalLock(hText);
                if (pText == IntPtr.Zero)
                {
                    return(null);
                }

                var rv = Marshal.PtrToStringUni(pText);
                UnmanagedMethods.GlobalUnlock(hText);
                return(rv);
            }
            finally
            {
                UnmanagedMethods.CloseClipboard();
            }
        }