home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / queue1.zip / CLIENT.C next >
C/C++ Source or Header  |  1988-10-10  |  1KB  |  54 lines

  1. /*
  2. ** Client Process
  3. */
  4.  
  5. #define INCL_DOSMEMMGR
  6. #define INCL_DOSQUEUES
  7. #define INCL_DOSPROCESS
  8. #define INCL_DOSERRORS
  9. #include <dos.h>
  10. #include <os2def.h>
  11. #include <bse.h>            /* MS OS/2 function declarations     */
  12.  
  13. char ServerMsg[]  = "Hello World!";
  14. char ServerName[] = "\\QUEUES\\SERVER.QUE";
  15.  
  16. void main (int argc, char *argv[], char *envp[])
  17. {
  18.    USHORT   rc;                 /* a return code                */
  19.    HQUEUE   QueueServer;        /* handle to the server's queue */
  20.    USHORT   ServerQPID;         /* server's process ID          */
  21.    SEL       ShrSegSel;
  22.    PSEL     SelPtr;
  23.    printf( "Starting Client Process\n" );
  24.  
  25.    /* Open a shared segment to put string in */
  26.    if(rc = DosAllocShrSeg(80,"\\SHAREMEM\\MYSEG",&ShrSegSel))
  27.     { printf("error code is %d\n",rc);
  28.       exit(1);
  29.     }
  30.    /* Build pointer to shared segment */
  31.  
  32.    FP_SEG(SelPtr) = ShrSegSel;
  33.    FP_OFF(SelPtr) = 0x0000;
  34.  
  35.    /* Copy the string to the segment */
  36.  
  37.    strcpy(SelPtr,ServerMsg);
  38.  
  39.    /* wait for queue to open */
  40.  
  41.    while(rc = DosOpenQueue( &ServerQPID, &QueueServer, ServerName ))
  42.       ;
  43.    printf( "rc from DosOpenQueue: %d\n", rc );
  44.  
  45.    /* Write to the queue */
  46.  
  47.    rc = DosWriteQueue( QueueServer, 0, (strlen(ServerMsg)+1 ), (PBYTE)SelPtr, 0 );
  48.    printf( "rc from DosWriteQueue: %d\n", rc );
  49.  
  50.    printf( "Quitting client process\n" );
  51.    DosFreeSeg(ShrSegSel);
  52.    DosCloseQueue( QueueServer );
  53. }
  54.