<--- Turn the page     (contents page)     Turn the page --->


C




Have you ever wanted to send a complete text file to the Windoze Clipboard? Well here is a small file in C that will allow you to send any text file smaller than 32k to the Clipboard.

CLIP.C below (see listing 1) takes any text file smaller than 32k as stdin and sends it to the clipboard. It is not a driver, so no need to load it at startup and take up precious memory.

First we get the text from stdin. Most of the time, this will be through redirection.

CLIP < filename.txt
However; you can run CLIP and type in your text, then press CTRL-Z and the ENTER key when you are done. If you made a mistake, press CTRL-C and CLIP will abort.

Next we check the clipboard interface. We call Interrupt 0x2F, service 0x1700. If this interrupt returns 0x1700 in the AX register, then the clipboard interface is not available.

Next we want to open and clear the clipboard. (Services 0x1701 & 0x1702)

We are going to get the stdin as simple as can be. The getc() macro does not get CR. So when a LF comes up, we have to send both a CR and a LF.
  do {
    if((tchar = getc(stdin)) == EOF) break;
    if (tchar == 0x0A) { *(buff++) = 0x0D; buffsize++; }
    *(buff++) = tchar;
    buffsize++;
  } while(1);
Now send it to the clipboard.
  inregs.x.ax = 0x1703;   //service number
  inregs.x.bx = FP_OFF(buffptr);   // offset of buffer
  inregs.x.cx = buffsize;          // buffer size
  inregs.x.dx = 0x01;              // text
  inregs.x.si = 0x00;              //
  segregs.es = FP_SEG(buffptr);    // segment of buffer
  int86x(0x2F,&inregs, &outregs, &segregs);
Then all we have to do is close the clipboard interface. (Service 0x1708)

That's it. See http://www.zekes.com/~blunt/clipbrd.html for source and documentation on how to use the clipboard interface in your programs. ¥




Listing 1
#include "dos.h"
#include "stdlib.h"
#include "stdio.h"

         int  retcode, i;
unsigned int  buffsize = 0;
         char buffer[32767];
         char *buff = buffer;
         char tchar;

void far *buffptr = buffer;

union REGS inregs, outregs;
struct SREGS segregs;

void main(void) {
  printf("\nSend STDIN to the clipboard.    Version 0.90");
  printf("\nCopyright  Forever Young Software  1984-1998\n");

  // get stdin
  do {
    if((tchar = getc(stdin)) == EOF) break;
    if (tchar == 0x0A) { *(buff++) = 0x0D; buffsize++; }
    *(buff++) = tchar;
    buffsize++;
  } while(1);

  // check to see if we can use the clipboard
  inregs.x.ax = 0x1700;
  int86(0x2F, &inregs, &outregs);
  if (outregs.x.ax == 0x1700) {
    printf("\nError with clipboard.");
    exit(-1);
  }

  // open the clipboard interface
  inregs.x.ax = 0x1701;
  int86(0x2F, &inregs, &outregs);

  //  and clear its contents
  inregs.x.ax = 0x1702;
  int86(0x2F, &inregs, &outregs);

  // put buff to the clipboard
  inregs.x.ax = 0x1703;
  inregs.x.bx = FP_OFF(buffptr);
  inregs.x.cx = buffsize;
  inregs.x.dx = 0x01;
  inregs.x.si = 0x00;
  segregs.es = FP_SEG(buffptr);
  int86x(0x2F,&inregs, &outregs, &segregs);

  //  and close it
  inregs.x.ax = 0x1708;
  int86(0x2F, &inregs, &outregs);

  exit(0);
}


<--- Turn the page     (contents page)     Turn the page --->

Page 11