04-14-2011 11:07 AM
I have a non LabWindows CVI application that outputs info to the clipboard and I am pulling the info off the clipboard with my CVI application. I would like to monitor the clipboard to know when a certain operation is completed on the other application and then pull the data and clear the clipboard so that I can monitor it again for new data when it becomes available.
Is there a way to clear the windows clipboard from inside my CVI application?
thnaks
04-14-2011 11:30 AM - edited 04-14-2011 11:32 AM
robojeff:
You may not like this replay, but once again I'm sending you to the Windows SDK. Have you thought about upgrading your CVI to the Full Development System?
Here's a knowledgebase article that states that Labwindows/CVI does not have an built in function to clear the clilpboard. It was written for CVI 8.0, but I beleive it's still the case.
http://digital.ni.com/public.nsf/allkb/C0FFAC8161753126862570E4005957AF
04-14-2011 11:42 AM
CVI ships with an example clipbord.cws that shows copy and paste to and from the clipboard. CVI's function ClipboardPutText() does not clear the clipboard if you try to paste a null string: it leaves the previous contents unchanged. You could use it to paste a space (or another character or string that your other app wouldn't paste) if that would help. You could even ClipboardPutText("Previous contents read by CVI."); and check the contents in a loop to see if they have changed.
Regardless of whether you use the SDK EmptyClipboard function or write you own text to the clipboard, you need to be careful that you don't empty it or write to it before you read the current contents. Be careful to avoid a timing problem where you read the contents, the other app writes to it, and then you clear it.
04-27-2011 12:20 PM
I have been playing around with the clipboard and I have another application that dumps test results to the clipboard when it is completed so I am sending an * To the clipboard and then polling the clipboard until it the test is finished as then the other application dumps its test results which over writes the *.
This seemed to work just fine but after a couple of attempts, I am getting an out of memory error. I have including a screen shot below(and attached) of my code and the error message. What am I doing wrong?
04-27-2011 12:46 PM
Robojeff:
Which is line 71?
From the small snapshot you posted, it looks like if CB[0] == 42, you free CB, but dummy still == 0, so you try to send the clipboard to CB, which you just free'ed.
It would be more helpful if you posted the source C file instead of just a JPG screen shot.
04-27-2011 01:29 PM
Line 71 is : ClipboardGetText (&CB, 0); // loop until cal test results are available
(lots of commented lines as I am going by trial and error on much of this code...)
Code is attached as I exceed the 10,000 character limit..
04-27-2011 02:51 PM - edited 04-27-2011 02:51 PM
Robojeff:
I took a closer look at ClipboardGetText(). It looks like I was wrong about your use of free(CB). ClipboardGetText() must allocate the memory it needs when you call it. Your code closely follows the help example for ClipboardGetText().
I ran your loop under different conditions and could not get it to fail with an error. I tried running with and without the expected character. I tried with a single character in the clipboard and with >2Meg of text there. I tried running the loop while I dumped text onto the clipboard.
I tried pasting graphics and reading it as text: I didn't get an error on ClipboardGetText(), but I did trying to read CB[0].
How big is the dataset you're writing to the clipboard?
Have you checked what is in the clipboard after you get the error?
04-27-2011 03:15 PM
@Al S wrote:
Robojeff:
I took a closer look at ClipboardGetText(). It looks like I was wrong about your use of free(CB). ClipboardGetText() must allocate the memory it needs when you call it. Your code closely follows the help example for ClipboardGetText().
I ran your loop under different conditions and could not get it to fail with an error. I tried running with and without the expected character. I tried with a single character in the clipboard and with >2Meg of text there. I tried running the loop while I dumped text onto the clipboard.
I tried pasting graphics and reading it as text: I didn't get an error on ClipboardGetText(), but I did trying to read CB[0].
How big is the dataset you're writing to the clipboard?
Have you checked what is in the clipboard after you get the error?
================
That is why I added the else free(CB): as I thought it might free up whatever memory that was being taken up during the many times that the clipboard is getting checked. The clipboard should only have * in it and getting the clipboard in the loop should not change the size of CB and how much memory that this takes should it?
When dummy = 1, here is the data that is on the clipboard:
Cal Signal Test Range: 6170 - 6821 Start Ch: 1PASS6545.0 6544.0 6561.0 6554.0 6550.0 6556.0 6548.0 6549.06564.0 6548.0 6558.0 6554.0 6554.0 6552.0 6554.0 6556.06561.0 6553.0 6559.0 6554.0 6559.0 6553.0 6551.0 6524.06532.0 6527.0 6523.0 6534.0 6535.0 6533.0 6538.0 6534.06570.0 6565.0 6573.0 6531.0 6529.0 6531.0 6519.0 6523.06526.0 6536.0 6529.0 6513.0 6503.0 6523.0 6516.0 6563.06536.0 6525.0 6527.0 6534.0 6523.0 6515.0 6524.0 6509.06526.0 6522.0 6534.0 6528.0 6527.0 6531.0 6508.0 6533.0
I do not need to set CB to ' ' before getting the clipboard on each pass of the loop do I?
04-28-2011 02:12 AM
I just had another couple thoughts on this, and figured that I would throw them out there....
Does the ClipboardGetText (as shown in the following line) automatically add a NULL character at the end of the string of data or do I need to do this?
ClipboardGetText (&CB, 0); // loop until cal test results are available
I am, not certain that there is a NULL characer at the end of the data on the clipboard and I didn't see one being added manually in code in the clipbord example, I only know that when I do a Ctl V in notepad there is only a couple of spaces after the data but this does not guarantee that the ClipboardGetText adds one...
I am speculating...Without a NULL character terminating the string, the size of CB could be enornmous.
Not sure if the OS version is pertinent to this but for what it is worth, I am running XP.
You didn;t have problems with this, what are you running on your machine or is it a memory available issue?
04-28-2011 11:01 AM
Robojeff:
I'm running CVI 2010 on Windows XP Pro 2002 Service Pack 3 with 3.5 Gb RAM.
It looks to me like ClipboardGetText appends the NULL character. I haven't seen any evidence to the contrary. As I copied various strings to the cllipboard, the string returned by ClipboardGetText always had the correct length: it expanded and shrank as needed.
The CVI Help for ClipboardGetText describes the first parameter as Pointer to the null-terminated string copied from the clipboard. I think it does the null-terminating. Since ClipboardGetText doesn't return the string length, how useful would that function be if it didn't terminate the string? You would never know where the string ended.
One of your earlier posts shows the data on the clipboard when dummy == 1. But when you get the error, dummy still == 0. What is the contents of the clipboard then? Leave the error dialog open, and switch to another app (like notepad) that accepts text from the clipboard, and paste it in.
Have you tried running your program with static data in the clipboard, without the other app (that writes to the clipboard) running?
Have you tried running the clipbord.prj sample project that ships with CVI while the app that writes to the clipboard is running and pasting from the clipboard repeatedly?