I am trying to write a method to copy some text to the clipboard, and leave
a copy of it there after the application has exited.
Sub CopyToClipboard(ByVal value As Object)
Dim data As New DataObject()
data.SetData(DataFormats.UnicodeText, True, value)
Clipboard.SetDataObject(data,True)
End Sub
When I test it, I get an exception:
System.Runtime.InteropServices.ExternalException: The requested clipboard
operation failed.
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
at System.Windows.Forms.Clipboard.SetDataObject(Objec t data, Boolean
copy)
at ClipName.PublicClipboard.CopyToClipboard(Object value)
However, the exception can be avoided if the Copy option is dropped from the
Clipboard.SetDataObject() method, but then the data is not available after
the application exits.
From this I guess the problem must be a matter of security.
Can someone tell me if it is indeed a security problem?
(and any pointers, as I am new to .NET security)
--
Thanks for any help,
Shayne H