Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <3988BD3E.479DFA86@ece.gatech.edu> Date: Wed, 02 Aug 2000 20:30:54 -0400 From: Charles Wilson X-Mailer: Mozilla 4.73 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: cygwin AT sourceware DOT cygnus DOT com Subject: Re: Clipboard from Cygwin? References: <003b01bffc0a$6da278a0$3c5350d8 AT guinness> <200008012327 DOT TAA29658 AT envy DOT delorie DOT com> <398783D9 DOT E25355B6 AT ece DOT gatech DOT edu> <200008020225 DOT WAA31321 AT envy DOT delorie DOT com> <39887033 DOT 1D40E2BA AT ece DOT gatech DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I dug around in my old code archives, and found the following (after a little cleanup). It may help someone add write capability to the /dev/clipboard. --Chuck #include #include #include #include #define CLIPCHUNK 1024 int main() { HANDLE hData; /* handle to clip data */ LPSTR lpData; /* pointer to clip data */ LPSTR lpszText; char chunk[CLIPCHUNK+1]; char *buf = NULL; char *buf_old = NULL; char *ptr; int len = 0; int numread; /* Since we have to copy to the clipboard all in one step, read entire stream into memory. However, let's try to do this using the minimum amount of memory, but keep allocating more if needed. */ do { numread = fread(chunk,sizeof(char),CLIPCHUNK,stdin); if(numread > 0) { if (buf) { if ((buf_old = malloc (len * sizeof(char))) == NULL) { fprintf(stderr,"internal error - out of memory"); return(FALSE); } memcpy(buf_old, buf, len); free(buf); } if ((buf = malloc ((len+numread) * sizeof(char))) == NULL) { fprintf(stderr,"internal error - out of memory"); return(FALSE); } if (buf_old) { memcpy(buf,buf_old,len); free(buf_old); } ptr = &(buf[len]); memcpy(ptr,chunk,numread); len += numread; } } while(!feof(stdin) && !ferror(stdin)); /* Allocate memory and copy the string to it */ if (!(hData = GlobalAlloc(GHND, len+1))) { return (TRUE); } if (!(lpData = GlobalLock(hData))) { return (TRUE); } strcpy((char *)lpData, buf); GlobalUnlock(hData); /* Clear the current contents of the clipboard, and set * the data handle to the new string. */ if (OpenClipboard(0)) { EmptyClipboard(); SetClipboardData(CF_TEXT, hData); CloseClipboard(); } hData = NULL; return (TRUE); } begin 664 putclip.c.gz M'XL("!V\B#D``W!U=&-L:7`N8P"=5&U/VS`0_KS^B@,DYI2,EVG?&$BH%)A6 M,41;:1)"*#27U2*Q(\>A AT ZK_?7>VDQ28F+1^<.I[\SW/O6Q)-KP<7T\CL<['_^TI/* M0I%():+>L@<`%R>7IZ,AS$\3FQP"[/5AGJ AT T1[`:9KDL(24%]/?8=G0UGEQ# M7G:VI:9X:-XSKIXG^-L>LF AT V3PP=M7JX:;/:.;CM=/W[.H,CN)R.1B^%=SI/ MWRI*:]R-,>6HR&"_O:NZ,)BDAST64*9CH AT AA@03OT8/3Y1-_[1Q=[O0.FHBK+)8Q>]./0P$J*PW+Z5;P(QH*++1YVH4+O(94LZ@*20M>4J\Y"H!CN:PL/B&7CZTJ<6'8D`P29 AT 4),,=UE M`\]TJOE%8^-:DQHQF7135FQ`HZ M+'Q?!8QK@-;`,)J=P$CT+JR`Z3\!O4&SZBAG$&LO=.CB!N%?L#FG)A!-"6': M9OD-V=XZ18A#NM AT W2`.3E5S$G:-NA#Q!CBMW+.8R1[&1,1F^@V![&^C.*(,D M:B?OQ+2L? MS4%