home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IPCX.ZIP / NPRMODE.C < prev    next >
C/C++ Source or Header  |  1989-09-20  |  1KB  |  73 lines

  1. /* nprmode.c RHS 5/1/89
  2.  *
  3.  *
  4.  This program opens the named pipe created by NPSERVER from the DOS
  5.  compatbility environment. After starting NPSERVER in a protected mode
  6.  session, you can bring the DOS box session into the foreground and run
  7.  this program with:
  8.  
  9.  NPRMODE
  10.  
  11.  */
  12. #include<string.h>
  13. #include<stdio.h>
  14. #include<stdlib.h>
  15. #include<fcntl.h>
  16. #include<io.h>
  17. #include<share.h>
  18. #include<sys\types.h>
  19. #include<sys\stat.h>
  20.  
  21. #include"nmpipe.h"
  22.  
  23. #if !defined(TRUE)
  24. #define TRUE 1
  25. #endif
  26.  
  27. char message[80];
  28.  
  29. void main(void);
  30.  
  31. void main(void)
  32.     {
  33.     char *mess = "Message from the DOS box!";
  34.     int    pipehandle, err, count = strlen(mess);
  35.  
  36.     if((pipehandle = sopen(NAMEDPIPE,(O_BINARY | O_RDWR),SH_DENYNO)) == -1)
  37.         {
  38.         printf("sopen failed, errno = %d\n",errno);
  39.         exit(0);
  40.         }
  41.  
  42.     while(TRUE)
  43.         {
  44.         strcpy(message,mess);
  45.             
  46.         if((err = write(pipehandle,message,count)) == -1)
  47.             {
  48.             printf("write failed, errno = %d\n",errno);
  49.             exit(0);
  50.             }
  51.  
  52.         count = 79;
  53.         if((err = read(pipehandle,message,count)) == -1)
  54.             {
  55.             printf("read failed, errno = %d\n",errno);
  56.             exit(0);
  57.             }
  58.             
  59.         if(err)
  60.             {
  61.             message[err] = NULL;
  62.             printf("Message received from the protected world: \"%s\"\n",message);
  63.             }
  64.         else
  65.             printf("No message from protected world\n");
  66.  
  67.         }
  68.  
  69.     close(pipehandle);
  70.     exit(0);
  71.     }
  72.  
  73.