Exemple #1
0
        public async Task <object> GetDataAsync(string format)
        {
            Dispatcher.UIThread.VerifyAccess();
            var i = OleRetryCount;

            while (true)
            {
                var hr = UnmanagedMethods.OleGetClipboard(out var dataObject);

                if (hr == 0)
                {
                    var wrapper = new OleDataObject(dataObject);
                    var rv      = wrapper.Get(format);
                    Marshal.ReleaseComObject(dataObject);
                    return(rv);
                }

                if (--i == 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                await Task.Delay(OleRetryDelay);
            }
        }
        public async Task <object> GetDataAsync(string format)
        {
            Dispatcher.UIThread.VerifyAccess();
            var i = OleRetryCount;

            while (true)
            {
                var hr = UnmanagedMethods.OleGetClipboard(out var dataObject);

                if (hr == 0)
                {
                    using var proxy   = MicroCom.MicroComRuntime.CreateProxyFor <Win32Com.IDataObject>(dataObject, true);
                    using var wrapper = new OleDataObject(proxy);
                    var rv = wrapper.Get(format);
                    return(rv);
                }

                if (--i == 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                await Task.Delay(OleRetryDelay);
            }
        }
Exemple #3
0
        public async Task <string[]> GetFormatsAsync()
        {
            Dispatcher.UIThread.VerifyAccess();
            while (true)
            {
                if (UnmanagedMethods.OleGetClipboard(out var dataObject) == 0)
                {
                    var wrapper = new OleDataObject(dataObject);
                    var formats = wrapper.GetDataFormats().ToArray();
                    Marshal.ReleaseComObject(dataObject);
                    return(formats);
                }

                await Task.Delay(100);
            }
        }
Exemple #4
0
        public async Task <object> GetDataAsync(string format)
        {
            Dispatcher.UIThread.VerifyAccess();
            while (true)
            {
                if (UnmanagedMethods.OleGetClipboard(out var dataObject) == 0)
                {
                    var wrapper = new OleDataObject(dataObject);
                    var rv      = wrapper.Get(format);
                    Marshal.ReleaseComObject(dataObject);
                    return(rv);
                }

                await Task.Delay(100);
            }
        }