home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / winnt / service / client.c next >
C/C++ Source or Header  |  1997-10-05  |  2KB  |  75 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1997  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   client.c
  9. //
  10. //  PURPOSE:  This program is a command line oriented
  11. //            demonstration of the Simple service sample.
  12. //
  13. //  FUNCTIONS:
  14. //    main(int argc, char **argv);
  15. //
  16. //  COMMENTS:
  17. //
  18. //
  19. #include <windows.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. VOID _CRTAPI1 main(int argc, char *argv[])
  25. {
  26.     char    inbuf[80];
  27.     char    outbuf[80];
  28.     DWORD   bytesRead;
  29.     BOOL    ret;
  30.     LPSTR   lpszPipeName = "\\\\.\\pipe\\simple";
  31.     LPSTR   lpszString = "World";
  32.     int     ndx;
  33.  
  34.     // allow user to define pipe name
  35.     for ( ndx = 1; ndx < argc-1; ndx++ )
  36.     {
  37.         if ( (*argv[ndx] == '-') || (*argv[ndx] == '/') )
  38.         {
  39.             if ( stricmp( "pipe", argv[ndx]+1 ) == 0 )
  40.             {
  41.                 lpszPipeName = argv[++ndx];
  42.             }
  43.             else if ( stricmp( "string", argv[ndx]+1 ) == 0 )
  44.             {
  45.                 lpszString = argv[++ndx];
  46.             }
  47.             else
  48.             {
  49.                 printf("usage: client [-pipe <pipename>] [-string <string>]\n");
  50.                 exit(1);
  51.             }
  52.         }
  53.         else
  54.         {
  55.             printf("usage: client [-pipe <pipename>] [-string <string>]\n");
  56.             exit(1);
  57.         }
  58.  
  59.     }
  60.  
  61.     strcpy( outbuf, lpszString );
  62.  
  63.     ret = CallNamedPipeA(lpszPipeName,
  64.                          outbuf, sizeof(outbuf),
  65.                          inbuf, sizeof(inbuf),
  66.                          &bytesRead, NMPWAIT_WAIT_FOREVER);
  67.  
  68.     if (!ret) {
  69.         printf("client: CallNamedPipe failed, GetLastError = %d\n", GetLastError());
  70.         exit(1);
  71.     }
  72.  
  73.     printf("client: received: %s\n", inbuf);
  74. }
  75.