/// <summary> /// Empties all the data structures added to the clipboard and flushes the clipboard. /// </summary> private void CleanAndFlushClipboard() { IOleDataObject oleDataObject = null; ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleGetClipboard(out oleDataObject)); if (oleDataObject == null) { return; } string sourceProjectPath = DragDropHelper.GetSourceProjectPath(oleDataObject); if (!String.IsNullOrEmpty(sourceProjectPath) && NativeMethods.IsSamePath(sourceProjectPath, this.GetMkDocument())) { ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleFlushClipboard()); int clipboardOpened = 0; try { ErrorHandler.ThrowOnFailure(clipboardOpened = UnsafeNativeMethods.OpenClipboard(IntPtr.Zero)); ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.EmptyClipboard()); } finally { if (clipboardOpened == 1) { ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.CloseClipboard()); } } } }