delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/08/02/20:28:54

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
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 <cwilson AT ece DOT gatech DOT edu>
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: <nZFGdDAMA1h5IwZi AT almide DOT demon DOT co DOT uk> <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>

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 <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#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)-<OK%.'K0JI4
M+ZK=^7%OJQ56-I7ZI:A(\ES/7IL9J7XY68J95`B#T;>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=[O<Z,2D0
MI>0.FHBK+)8Q>]./0P$J*PW+Z5;P(QH*++1YVH4+O<!'-#&E83]68(T+'9Q3
M?D164%=4&O=>(94LZ@*20M>4J\Y"H!CN:PL/B&7CZTJ<6'8D`P29 AT 4),,=UE
M`\]TJOE<!H\`G,C(^"L<WW$EGU%G AT GF+XI;\F+M*18?!56:B\3Z&_2A(E[T/
M_*R@,D3TEZ_.%H3H*N-[$027H0_KKT41'/G*1=XS!*!?5E*SVDQ0%FA,O.EZ
M224YT$T;^`2Z7B-GD_)L/`W:VBAQ=C(:#QOQRG_(>%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+<P!M1`ZR4,W]P-DQL*#=*&=F;@&\(M)*!DCN`\U_=)[L*(\XO+4U?.
MG0,NP;*=3V80Q.1Z.O3MO.I"^875!AKIV8,/_Z\(?%*"3)3P&R?RL5Q7>2L?
M<ZKR+JHG+*`?Y$B.;LG4QM`*(>S4%<I6W`@OED_LJ*G0.O^^4[J%VFUD%BE<
M!-IVO:%CK8'[HT0U:"**_36$PZ*T3YVJG?HQVE;*^8O!V=UD^',2PSH<("2Z
8PM?^CN9YX+==SZ_(7/7^`&.H&'3=!@``
`
end

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019