Example #1
0
        /// <summary>
        /// Retrieves data at the specified clipboard format Id, and converts it into a managed object.
        /// </summary>
        protected virtual T GetFormatObject <T>(uint format, IDataConverter <T> converter)
        {
            ThrowIfDisposed();

            var hglobal = NativeMethods.GetClipboardData(format);

            if (hglobal == IntPtr.Zero)
            {
                var err = Marshal.GetLastWin32Error();
                if (err == 0)
                {
                    throw new Exception("Clipboard data could not be retrieved for this format, is it currently present?");
                }
                else
                {
                    throw new Win32Exception(err);
                }
            }

            return(converter.ReadFromHGlobal(hglobal));
        }