473,781 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Requested clipboard operation did not succeed

Wow.....this is darned odd....

I have an app that integrates with other applications.

It registers a global hotkey with Windows. When the hotkey executes
it sends a CTRL-C to the active window (any application) to copy
whatever text is selected to the clipboard. It then issues a C#
Clipboard.GetTe xt(...) and does some processing with this string.

All is good, no errors thus far.

My application has an option to then copy the processed text back to
the clipboard and send a CTRL-V to the original window to paste it
back in. Here is where the wierdness begins to happen. This optional
"PASTE BACK TO ORIGINAL WINDOW" code works without error. All I do is
issue a Clipboard.SetTe xt(...) and then send the keystroke CTRL-V to
the original window. And when this code executes all behaves as
planned.

BUT....where the problem comes in is the NEXT TIME I try to activate
my hotkey. When my app tries to send the CTRL-C and issue a
Clipboard.GetTe xt(...) again. I receive the exception "Requested
clipboard operation did not succeed". (from Clipboard.GetTe xt() )

Through trial and error I have determined it's Clipboard.SetTe xt()
that causes my problem. In other words, this happens even if I
comment out the CTRL-V lines of code. And the problem doesn't happen
if I do not execute Clipboard.SetTe xt() but still send the CTRL-V
anyway.

I've added lots of diagnostic code to try and track this down. Added
some code to issue a Win32 GetOpenClipboar dWindow() and then report
the process that currently has the clipboard open. It's NOTEPAD.EXE
(the "other" application I've been using for my testing).

It is NOT specific to NOTEPAD. I've tried other applications with the
same results. Anytime I execute my "paste" code, the next time I try
to read the clipboard it's locked by whatever the other application
is.

This ONLY happens when I perform the optional "paste back to original
window" code. I can repeatedly do the "copy from original window"
code over and over again without failure. So it seems to be
something I am doing - not something the other app is doing.

This does not last FOREVER. I've added a loop in my "read the
clipboard" method that waits until GetOpenClipboar dWindow() returns
null before trying to read the clipboard. After a few seconds of
retrying...the clipboard eventually frees up and I can read no
problem. I would just leave this code in there and call it "fixed"
but this long delay really detracts from the usefullness of my
application.

Here is the "paste to original window" code I am using (the problem
only occurs after I execute this code)...

if (hwndActiveWind ow == IntPtr.Zero)
return; //...no original active window to paste to

// Copy translated text from active tab to clipboard...
Clipboard.SetTe xt("Some text here"); // <<<APPEARS TO BE
THE OFFENDING LINE OF CODE

// Make sure original active window is back to being
active again...
SetForegroundWi ndow(hwndActive Window);

// Send a CTRL-V to paste clipboard data to orignal active
window...
keybd_event(0x1 1, 0, 0, (IntPtr)0); //...CTRL key down
keybd_event(0x5 6, 0, 0, (IntPtr)0); //...V key down
keybd_event(0x5 6, 0, 0x02, (IntPtr)0); //...V key up
keybd_event(0x1 1, 0, 0x02, (IntPtr)0); //...CTRL key up

That's it. Nothing too complicated.

I've searched the web in vain for a clue as to what is going on
here.

Can somebody offer some insight? I value what's left of my hair too
much to pull it out over something that should be very simple...

-Figmo

Jun 27 '07 #1
1 18670
Wow - this just keeps getting wierder. I've simplified the problem
and it still makes no sense to me.

The problem is basically that Windows apps such as Notepad and
IExplorer (the only 2 I've tested with) seem to "hang on" to the
clipboard after a use keybd_event() to send a CTRL-C to that
application. But only if I've previously done a paste using CTRL-V.

I've eliminated my code to the the paste. I can now make the problem
come and go just by pressing CTRL-V on the keyboard myself. If I
don't paste, my code that sends the CTRL-C using keybd_event() works
every time. If I paste text into notepad (either by pressing CTRL-V
myself, or using keybd_event() to do it) then after issuing a CTRL-C
using keybd_event() the clipboard stays locked by notepad for several
seconds before I can access it.

What's odd is if I eliminate my keybd_event() CTRL-C code and just
manually press the CTRL-C and CTRL-V when needed - all works fine. My
program can read the clipboard and write the clipboard with zero
delays.

So this suggests it's in my "copy" code. But my "copy" code is about
as simple as it can get. Here it is...

keybd_event(0x1 1, (byte)NativeWIN 32.MapVirtualKe y(0x11,0), 0,
(IntPtr)0); //...CTRL key down
keybd_event(0x4 3, (byte)NativeWIN 32.MapVirtualKe y(0x43, 0), 0,
(IntPtr)0); //...C key down
keybd_event(0x4 3, (byte)NativeWIN 32.MapVirtualKe y(0x43, 0), 0x02,
(IntPtr)0); //...C key up
keybd_event(0x1 1, (byte)NativeWIN 32.MapVirtualKe y(0x11, 0), 0x02,
(IntPtr)0); //...CTRL key up
string strClip = Clipboard.GetTe xt(); //<<<THROWS EXCEPTION IF I"VE
PREVSIOUSLY DONE A PASTE

That's it. I've tried putting Sleep()'s betwee the copy and my
GetText(). I've tried clearing the clipboard before doing the CTRL-
C. I've tried using SendInput() instead of keybd_event(). The ONLY
thing I've found that has an effect is to comment out my keybd_event()
lines and manually pressing CTRL-C before pressing the hotkey that
invokes this code. That works EVERY TIME NO PROBLEM.

So what the hell is the difference between me pressing CTRL-C on the
keyboard, and using keybd_event() as above??

-Bill

Jun 28 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2236
by: xyz | last post by:
I have a menu item to handle clipboard actions (cut, copy, paste). When I paste text that I copied from a Hungarian web page, the display looks normal on my RichTextBox, but the text retrieved from the clipboard is corrupted. For example, a U with double accent ( byte code x'FB' ) is replaced by a question mark in my txtEdit.Text after a Paste operation. It seems that the Clipboard.GetText() is changing the data. How is it possible to...
0
473
by: Dennis | last post by:
Greetings, I am having a wierd problem with .net accessing the clipboard on certain machines. The code copies the RTF formatted data from the clipboard. I first try and retrieve the clipboard via the Clipboard.GetDataObject call : IDataObject ido = Clipboard.GetDataObject(); But the above call will return with the exception :
0
2004
by: Christopher | last post by:
Hello, First, I appologize for the length but I want to get all the facts down so as not to waste any time :) I'm trying to allow the user of my C# app to copy a DataGrid full of double values to the clipboard (via ctrl-C, edit->copy, etc). They can then paste these values wherever (but in particular, excel). I've searched the web fairly exhaustively and cannot find an answer to this. Every time someone asks, somone answers with the...
0
1285
by: geo24 | last post by:
Have a problem with clipboard. Using the standard way for copying the image data: read the image into "myBitmap" copy the image into clipboard: DataObject myData = new DataObject(); myData.SetData( DataFormats.Dib,true,myBitmap); Clipboard.SetDataObject(myData,true);
8
9810
by: Dinesh Jain | last post by:
Hi all, I encountered a serious problem while working with clipboard class in VB.NET. I want to simulate cut-copy-paste operation with my application and Windows Explorer. User can copy files from Explorer and paste it into my application & vice-a-versa. My question is- How can I determine if user has copied or cut the files from Windows Explorer? I want to differentiate cut & copy.
15
12305
by: Peter Duniho | last post by:
I'm trying to use .NET and C# to draw a metafile copied to the clipboard by another application (Word 2003 in this case, but it shouldn't matter). I naively thought that I'd be able to use the Clipboard class to get an EnhancedMetafile or MetafilePict object from the Clipboard, use that to create a new Metafile object, and then draw that Metafile object using Graphics.DrawImage. It doesn't seem to be that simple.
1
4211
by: Ludwig Wittgenstein | last post by:
Hi, all. Here's the scenario: I embedd a .txt file in Word as OLE object, then I copy it (manually), so now it's on the clipboard. How do I programatically (in C#) get that OLE object file from the clipboard and dump it into an actual text file on the file system? All I would like to know is how to grab the OLE from the clipboard and transform it into a file, stream, string, or anything that gives me the internal contents of that txt...
5
6883
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text" widget in Tkinter? Here is my first attempt with just trying to print out the image data: ----------------- def pasteImg(tgt): global clipboardEnabled if not clipboardEnabled: return
1
3316
by: info | last post by:
Hi All, I am struggling with this from 48 hours and cannot succeed, of course I've tried: DataObject dObj = new DataObject(); dObj.SetData(DataFormats.Bitmap, false, bitmap); Clipboard.SetDataObject(dObj, true);
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.