home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05022a < prev    next >
Text File  |  1992-04-21  |  7KB  |  197 lines

  1. #define  MAIN
  2. #include <dos.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. /*
  6. ******************************************************************
  7. Title:      CLIP.C
  8. Author:     Thomas W. Olsen
  9. Version:    3.0
  10. Compiler:   Microsoft C 6.0
  11.             cl /AL /Zi clip.c
  12. ******************************************************************
  13. */
  14. #define GET_WINOLDAP_VERSION        0x1700
  15. #define OPEN_CLIPBOARD              0x1701
  16. #define EMPTY_CLIPBOARD             0x1702
  17. #define SET_CLIPBOARD_DATA          0x1703
  18. #define GET_CLIPBOARD_DATA_SIZE     0x1704
  19. #define GET_CLIPBOARD_DATA          0x1705
  20. #define CLOSE_CLIPBOARD             0x1708
  21. #define COMPACT_CLIPBOARD           0x1709
  22.  
  23. #define TEXT_FORMAT                 1
  24. #define BITMAP_FORMAT               2
  25. #define METAFILE_FORMAT             3
  26. #define SYLK_FORMAT                 4
  27. #define DIF_FORMAT                  5
  28. #define TIFF_FORMAT                 6
  29. #define OEM_TEXT                    7
  30.     
  31. int ErrorExit(char *message)
  32. {
  33.     printf(message);
  34.     exit(-1);
  35. }
  36.                                 
  37. int main(int argc, char *argv[])
  38. {
  39.     long clipboardSize;
  40.     char far *clipboardBuffer;
  41.     union REGS regs;
  42.     struct SREGS sregs;
  43.  
  44.     /*****************************************************/
  45.  
  46.     regs.x.ax = GET_WINOLDAP_VERSION;
  47.     int86x(0x2F, ®s, ®s, &sregs);
  48.  
  49.     if (regs.x.ax == GET_WINOLDAP_VERSION)  
  50.         ErrorExit("Windows Not Loaded or Clipboard Not Supported.\n");
  51.  
  52.     /*****************************************************/
  53.  
  54.     regs.x.ax = OPEN_CLIPBOARD;
  55.     int86x(0x2F, ®s, ®s, &sregs);
  56.  
  57.     if (regs.x.ax == 0)
  58.         ErrorExit("Clipboard in Use.\n");
  59.  
  60.     /*****************************************************/
  61.  
  62.     regs.x.ax = GET_CLIPBOARD_DATA_SIZE;            /* AX = Function No. */
  63.     regs.x.dx = TEXT_FORMAT;                        /* DX = Data Format */
  64.     int86x(0x2F, ®s, ®s, &sregs);
  65.  
  66.     if ((clipboardSize = ((long) regs.x.dx << 4L) + regs.x.ax) == 0L)
  67.     {
  68.         if ((clipboardBuffer = malloc(1024)))
  69.         {
  70.             strcpy(clipboardBuffer, "This is a test of the Clipboard!!!");
  71.  
  72.             regs.x.ax = SET_CLIPBOARD_DATA;         /* AX = Function No. */
  73.             regs.x.dx = TEXT_FORMAT;                /* DX = Data Format */
  74.             sregs.es  = FP_SEG(clipboardBuffer);    /* ES:BX -> Clip Buffer */
  75.             regs.x.bx = FP_OFF(clipboardBuffer);
  76.             regs.x.si = 0;                          /* SI:CX = (long) Size */
  77.             regs.x.cx = strlen(clipboardBuffer);
  78.             int86x(0x2F, ®s, ®s, &sregs);
  79.         }
  80.     }
  81.     else
  82.     {
  83.         clipboardBuffer = malloc((int) clipboardSize);
  84.  
  85.         regs.x.ax = GET_CLIPBOARD_DATA;             /* AX = Function No. */
  86.         regs.x.dx = TEXT_FORMAT;                    /* DX = Data Format */ 
  87.         sregs.es  = FP_SEG(clipboardBuffer);        /* ES:BX -> Clip Buffer */
  88.         regs.x.bx = FP_OFF(clipboardBuffer);
  89.         int86x(0x2F, ®s, ®s, &sregs);
  90.  
  91.         if (regs.x.ax != 0)                         /* Successful? */
  92.             printf("Clipboard Contains [%s]\n", clipboardBuffer);
  93.     }
  94.  
  95.     regs.x.ax = CLOSE_CLIPBOARD;                    /* AX = Function No. */
  96.     int86x(0x2F, ®s, ®s, &sregs);
  97.     free(clipboardBuffer);                          /* Clean Up */
  98. }
  99. #define  MAIN
  100. #include <dos.h>
  101. #include <stdlib.h>
  102. #include <malloc.h>
  103. /*
  104. ******************************************************************
  105. Title:      CLIP.C
  106. Author:     Thomas W. Olsen
  107. Version:    3.0
  108. Compiler:   Microsoft C 6.0
  109.             cl /AL /Zi clip.c
  110. ******************************************************************
  111. */
  112. #define GET_WINOLDAP_VERSION        0x1700
  113. #define OPEN_CLIPBOARD              0x1701
  114. #define EMPTY_CLIPBOARD             0x1702
  115. #define SET_CLIPBOARD_DATA          0x1703
  116. #define GET_CLIPBOARD_DATA_SIZE     0x1704
  117. #define GET_CLIPBOARD_DATA          0x1705
  118. #define CLOSE_CLIPBOARD             0x1708
  119. #define COMPACT_CLIPBOARD           0x1709
  120.  
  121. #define TEXT_FORMAT                 1
  122. #define BITMAP_FORMAT               2
  123. #define METAFILE_FORMAT             3
  124. #define SYLK_FORMAT                 4
  125. #define DIF_FORMAT                  5
  126. #define TIFF_FORMAT                 6
  127. #define OEM_TEXT                    7
  128.     
  129. int ErrorExit(char *message)
  130. {
  131.     printf(message);
  132.     exit(-1);
  133. }
  134.                                 
  135. int main(int argc, char *argv[])
  136. {
  137.     long clipboardSize;
  138.     char far *clipboardBuffer;
  139.     union REGS regs;
  140.     struct SREGS sregs;
  141.  
  142.     /*****************************************************/
  143.  
  144.     regs.x.ax = GET_WINOLDAP_VERSION;
  145.     int86x(0x2F, ®s, ®s, &sregs);
  146.  
  147.     if (regs.x.ax == GET_WINOLDAP_VERSION)  
  148.         ErrorExit("Windows Not Loaded or Clipboard Not Supported.\n");
  149.  
  150.     /*****************************************************/
  151.  
  152.     regs.x.ax = OPEN_CLIPBOARD;
  153.     int86x(0x2F, ®s, ®s, &sregs);
  154.  
  155.     if (regs.x.ax == 0)
  156.         ErrorExit("Clipboard in Use.\n");
  157.  
  158.     /*****************************************************/
  159.  
  160.     regs.x.ax = GET_CLIPBOARD_DATA_SIZE;            /* AX = Function No. */
  161.     regs.x.dx = TEXT_FORMAT;                        /* DX = Data Format */
  162.     int86x(0x2F, ®s, ®s, &sregs);
  163.  
  164.     if ((clipboardSize = ((long) regs.x.dx << 4L) + regs.x.ax) == 0L)
  165.     {
  166.         if ((clipboardBuffer = malloc(1024)))
  167.         {
  168.             strcpy(clipboardBuffer, "This is a test of the Clipboard!!!");
  169.  
  170.             regs.x.ax = SET_CLIPBOARD_DATA;         /* AX = Function No. */
  171.             regs.x.dx = TEXT_FORMAT;                /* DX = Data Format */
  172.             sregs.es  = FP_SEG(clipboardBuffer);    /* ES:BX -> Clip Buffer */
  173.             regs.x.bx = FP_OFF(clipboardBuffer);
  174.             regs.x.si = 0;                          /* SI:CX = (long) Size */
  175.             regs.x.cx = strlen(clipboardBuffer);
  176.             int86x(0x2F, ®s, ®s, &sregs);
  177.         }
  178.     }
  179.     else
  180.     {
  181.         clipboardBuffer = malloc((int) clipboardSize);
  182.  
  183.         regs.x.ax = GET_CLIPBOARD_DATA;             /* AX = Function No. */
  184.         regs.x.dx = TEXT_FORMAT;                    /* DX = Data Format */ 
  185.         sregs.es  = FP_SEG(clipboardBuffer);        /* ES:BX -> Clip Buffer */
  186.         regs.x.bx = FP_OFF(clipboardBuffer);
  187.         int86x(0x2F, ®s, ®s, &sregs);
  188.  
  189.         if (regs.x.ax != 0)                         /* Successful? */
  190.             printf("Clipboard Contains [%s]\n", clipboardBuffer);
  191.     }
  192.  
  193.     regs.x.ax = CLOSE_CLIPBOARD;                    /* AX = Function No. */
  194.     int86x(0x2F, ®s, ®s, &sregs);
  195.     free(clipboardBuffer);                          /* Clean Up */
  196. }
  197.