home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 14 / testclip.c < prev    next >
C/C++ Source or Header  |  1992-06-03  |  1KB  |  59 lines

  1. /* 
  2. TESTCLIP.C -- throw-away test program for Windows clipboard API
  3.  
  4. Copyright (c) 1992 Ziff Davis Communications
  5. PC Magazine * Andrew Schulman (June 1992)
  6. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <malloc.h>
  11. #include "winclip.h"
  12.  
  13. static int clip_open = 0;
  14.  
  15. void fail(char *s)
  16. {
  17.     if (clip_open)
  18.         CloseClipboard();
  19.     puts(s);
  20.     exit(1);
  21. }
  22.  
  23. main()
  24. {
  25.     unsigned long len;
  26.     char far *buf;
  27.  
  28.     if (! IdentifyWinOldApVersion())
  29.         fail("This program must run in a DOS box "
  30.              "under Enhanced mode Windows");
  31.  
  32.     /* MUST do OpenClipboard before GetClipboardDataSize */
  33.     if (! OpenClipboard())
  34.         fail("Can't open clipboard -- try again later");
  35.     clip_open = 1;
  36.  
  37.     if ((len = GetClipboardDataSize(CF_TEXT)) == 0)
  38.         fail("No text in clipboard");
  39.  
  40.     /* printf("%lu bytes of text in clipboard\n", len); */
  41.  
  42.     /* the following can be removed in 32-bit code */
  43.     if (len > 0xFFF0UL)
  44.         fail("Sorry, can't handle more than 64k of text");
  45.  
  46.     if ((buf = _fmalloc(len+1)) == 0) /* add 1 for NULL terminate */
  47.         fail("Insufficient memory");
  48.  
  49.     if (! GetClipboardData(CF_TEXT, buf))
  50.         fail("Couldn't get clipboard text");
  51.  
  52.     /* finally, we've got our text */
  53.     CloseClipboard();      /* close it BEFORE displaying string */
  54.     buf[len] = '\0';       /* add NULL terminate */
  55.     printf("%Fs\n", buf);  /* print FAR string */
  56.     return 0;
  57. }
  58.  
  59.