home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / WINDOWS / PUTCLIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-04  |  1.3 KB  |  57 lines

  1. /* 
  2. PUTCLIP.C -- put text on Windows clipboard
  3. */ 
  4.  
  5. #include <stdlib.h> 
  6. #include <stdio.h> 
  7. #include <string.h> 
  8. #include <dos.h> 
  9. #include <io.h> 
  10. #include <fcntl.h> 
  11. #include <pltypes.h>
  12. #include "winclip.h" 
  13.  
  14. #ifdef __WATCOMC__
  15. #define _read read
  16. #define _open open
  17. #define _close close
  18. #define _filelength filelength
  19. #endif
  20.  
  21. void fail(char *s) { puts(s); exit(1); } 
  22.  
  23. int main(int argc, char *argv[]) 
  24.     int f, len, maj, min; 
  25.     int rc; // number of bytes read 
  26.     char *p; 
  27.  
  28.     if (! WinOldApVersion(&maj, &min)) 
  29.       fail("This program requires Windows Enhanced mode"); 
  30.  
  31.     if (argc < 2) 
  32.         fail("usage: putclip [filename]"); 
  33.      
  34.     f = _open(argv[1], O_RDONLY);
  35.     if (f == -1)
  36.         fail("can't open file"); 
  37.     len = _filelength(f); 
  38.     if ((p = malloc(len+1)) == 0) 
  39.         fail("insufficient memory"); 
  40.     rc = _read(f, p, len);
  41.     if (rc < 0)
  42.         fail("can't read file"); 
  43.     _close(f);
  44.     p[rc] = '\0';  // must be NULL terminated 
  45.      
  46.     fputs("putclip ", stdout); 
  47.     switch (PutClipStrLen(p, rc+1)) // include space for NULL 
  48.     { 
  49.         case 0:   puts("failed"); break; 
  50.         case 1:   puts("successful"); break; 
  51.         case -1:  puts("requires Windows Enhanced mode"); break; 
  52.     } 
  53.     free(p); 
  54.     return 0; 
  55.