From: asit on
Here is a code I wrote to log all clipboard text in the log file.

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

void myfree();
FILE *fp;
char *p;
HANDLE clip;

int main()
{
HANDLE clip;
p=(char*)malloc(1);
*p='\0';
fp= fopen("log.txt", "a");
atexit(myfree);
if (OpenClipboard(NULL))

while(true)
{
clip = GetClipboardData(CF_TEXT);
if(strcmp(p,(char*)clip)!=0)
{
free(p);
p = (char*)malloc(strlen((char*)clip)+1);
strcpy(p,(char*)clip);
fprintf(fp,"%s",p);
}
Sleep(500);
}

}

void myfree()
{
free(p);
if(fp!=NULL)
fclose(fp);
free(clip);
}


The code runs fine. But as the program runs, why can't I do as usual
copy-paste stuff ??
From: Preben Friis on

"asit" <lipun4u(a)gmail.com> wrote in message
news:f1284106-4a97-4ecb-b071-751f97e70267(a)t18g2000vbj.googlegroups.com...
> The code runs fine. But as the program runs, why can't I do as usual
> copy-paste stuff ??

http://msdn.microsoft.com/en-us/library/ms649048(VS.85).aspx
"The OpenClipboard function opens the clipboard for examination and prevents
other applications from modifying the clipboard content. "

.... so you are preventing other applications from using it.

Change your code to close the clipboard again....

while(true)
{
if (OpenClipboard(NULL))
{
clip = GetClipboardData(CF_TEXT);
if(strcmp(p,(char*)clip)!=0)
{
free(p);
p = (char*)malloc(strlen((char*)clip)+1);
strcpy(p,(char*)clip);
fprintf(fp,"%s",p);
}
CloseClipboard();
}
Sleep(500);
}

From: asit on
On Nov 5, 12:16 am, "Preben Friis" <no...(a)technologist.com> wrote:
> "asit" <lipu...(a)gmail.com> wrote in message
>
> news:f1284106-4a97-4ecb-b071-751f97e70267(a)t18g2000vbj.googlegroups.com...
>
> > The code runs fine. But as the program runs, why can't I do as usual
> > copy-paste stuff ??
>
> http://msdn.microsoft.com/en-us/library/ms649048(VS.85).aspx
> "The OpenClipboard function opens the clipboard for examination and prevents
> other applications from modifying the clipboard content. "
>
> ... so you are preventing other applications from using it.
>
> Change your code to close the clipboard again....
>
>         while(true)
>         {
>             if (OpenClipboard(NULL))
>             {
>                 clip = GetClipboardData(CF_TEXT);
>                 if(strcmp(p,(char*)clip)!=0)
>                 {
>                     free(p);
>                     p = (char*)malloc(strlen((char*)clip)+1);
>                     strcpy(p,(char*)clip);
>                     fprintf(fp,"%s",p);
>                 }
>                 CloseClipboard();
>             }
>             Sleep(500);
>         }

thank you buddy...it works...