/*---------------------------------------------------------------------------- DOS access to Windows clipboard Chris Giese http://SisAndHappy.com/ChrisGiese/ This code is public domain (no copyright). You can do whatever you want with it. Release date: September 16, 2008 Compile with Turbo C or 16-bit Watcom C ----------------------------------------------------------------------------*/ #include #include #include /****************************************************************************/ int main(void) { static const char to[] = "Hello"; /**/ unsigned long len; struct SREGS sregs; union REGS regs; char *from; /* identify WINOLDAP version */ regs.x.ax = 0x1700; int86(0x2F, ®s, ®s); if(regs.x.ax == 0x1700) { printf("Can't access Windows clipboard\n"); return 1; } /* open clipboard (ignore return value) */ regs.x.ax = 0x1701; int86(0x2F, ®s, ®s); /* check if any text already in clipboard */ regs.x.ax = 0x1704; regs.x.dx = 0x01; int86(0x2F, ®s, ®s); len = regs.x.dx * 0x10000L + regs.x.ax; if(len == 0) printf("No text in Windows clipboard\n"); else { from = malloc(len); if(from == NULL) printf("Not enough memory to read Windows clipboard\n"); else { regs.x.ax = 0x1705; regs.x.dx = 0x01; sregs.es = FP_SEG(from); regs.x.bx = FP_OFF(from); int86x(0x2F, ®s, ®s, &sregs); if(regs.x.ax == 0) printf("Error reading Windows clipboard\n"); else printf("Text in Windows clipboard is:\n%s\n", from); free(from); } } /* set clipboard data */ printf("Writing to Windows clipboard...\n"); regs.x.ax = 0x1703; /* 1=text, 2=bitmap, 3=.WMF...see Ralf Brown's list for more: */ regs.x.dx = 0x01; regs.x.si = 0; regs.x.cx = sizeof(to); sregs.es = FP_SEG(to); regs.x.bx = FP_OFF(to); int86x(0x2F, ®s, ®s, &sregs); if(regs.x.ax == 0) printf("Error writing Windows clipboard\n"); /* close clipboard */ regs.x.ax = 0x1708; int86(0x2F, ®s, ®s); return 0; }