469,616 Members | 1,823 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

How to copy to the Clipboard and make data public

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
Nov 20 '05 #1
2 3093
Hi, I could not repo your issue on Visual Studio .NET 2003.

Would you tell me what you passed in as 'value' for 'CopyToClipboard'?

Thanks,

--
Huy Nguyen, Visual Basic team.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 20 '05 #2
I was passing a string.
However now I cannot reproduce the problem either.

"Huy Nguyen [MSFT]" <hu**@online.microsoft.com> wrote in message
news:9o*************@cpmsftngxa07.phx.gbl...
Hi, I could not repo your issue on Visual Studio .NET 2003.

Would you tell me what you passed in as 'value' for 'CopyToClipboard'?

Thanks,

--
Huy Nguyen, Visual Basic team.

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Risto Heinonen | last post: by
2 posts views Thread by adam | last post: by
1 post views Thread by andrew | last post: by
2 posts views Thread by Keith | last post: by
7 posts views Thread by lgbjr | last post: by
9 posts views Thread by Alan T | last post: by
reply views Thread by Curious | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.