The requested clipboard operation failed

I am using vb.net 2003 and sometimes this error occurs. Does anyone know how this error occurs and how to fix it?

Error: failed clipboard operation

+3
source share
3 answers

I searched this question to see what I would see, and many people asked this question, and none of them received a solid answer ...

So, I went to the MSDN documentation and found a note explaining that most of the people who asked this question describe ... The symptom usually appears when the user switches to another application while the code is running. A note is provided below with reference to the following documentation:

Windows , .

. , . System.Runtime.Serialization . , . , MemoryStream MemoryStream SetData.

Clipboard , (STA). , , STAThreadAttribute .

. - DataObject class, , .NET Framework , . Win32 (API). . 323530, " ", : http://support.microsoft.com.

http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx

, , . , Excel ( , , ). , Interop API excel, , , . Excel , . Windows, , , .

, , , , +1 .

+5

:

Clipboard.Clear();
...
Clipboard.SetText(...);

Clipboard.Clear() user32.dll:

[DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();

[DllImport("user32.dll")]
private static extern bool OpenClipboard(IntPtr hWndNewOwner);

[DllImport("user32.dll")]
static extern bool EmptyClipboard();

[DllImport("user32.dll", SetLastError=true)]
static extern bool CloseClipboard();

...

IntPtr handleWnd = GetOpenClipboardWindow();
OpenClipboard(handleWnd);
EmptyClipboard();
CloseClipboard();

...

Clipboard.SetText(...);

# , vb .

+1

Is there any chance that UltraVNC is working. I have problems when this application runs in the background on the client computer side. When I close VNC, I can successfully copy to the clipboard. This is not a really satisfactory solution, but at least I know in my case the source of the problem.

0
source

Source: https://habr.com/ru/post/1758136/


All Articles