home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / hello / hellos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.7 KB  |  143 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                         hello Example
  5.  
  6.     FILE:       hellos.c
  7.  
  8.     USAGE:      hellos  -p protocol_sequence
  9.                         -e endpoint
  10.                         -m max calls
  11.                         -n min calls
  12.                         -f flag for RpcServerListen
  13.  
  14.     PURPOSE:    Server side of RPC distributed application hello
  15.  
  16.     FUNCTIONS:  main() - registers server as RPC server
  17.  
  18.     COMMENTS:   This version of the distributed application that prints
  19.                 "hello, world" (or other string) on the server features
  20.                 a client that manages its connection to the server.
  21.                 It uses the binding handle hello_IfHandle, defined in
  22.                 the file hello.h.
  23.  
  24. ****************************************************************************/
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <ctype.h>
  29. #include "hello.h"    // header file generated by MIDL compiler
  30.  
  31. #define PURPOSE \
  32. "This Microsoft RPC Version 1.0 sample program demonstrates\n\
  33. the use of the [string] attribute. For more information\n\
  34. about the attributes and the RPC API functions, see the\n\
  35. RPC programming guide and reference.\n\n"
  36.  
  37. void Usage(char * pszProgramName)
  38. {
  39.     fprintf(stderr, "%s", PURPOSE);
  40.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  41.     fprintf(stderr, " -p protocol_sequence\n");
  42.     fprintf(stderr, " -e endpoint\n");
  43.     fprintf(stderr, " -m maxcalls\n");
  44.     fprintf(stderr, " -n mincalls\n");
  45.     fprintf(stderr, " -f flag_wait_op\n");
  46.     exit(1);
  47. }
  48.  
  49. /* main:  register the interface, start listening for clients */
  50. void _CRTAPI1 main(int argc, char * argv[])
  51. {
  52.     RPC_STATUS status;
  53.     unsigned char * pszProtocolSequence = "ncacn_np";
  54.     unsigned char * pszSecurity         = NULL;
  55.     unsigned char * pszEndpoint         = "\\pipe\\hello";
  56.     unsigned int    cMinCalls           = 1;
  57.     unsigned int    cMaxCalls           = 20;
  58.     unsigned int    fDontWait           = FALSE;
  59.     int i;
  60.  
  61.     /* allow the user to override settings with command line switches */
  62.     for (i = 1; i < argc; i++) {
  63.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  64.             switch (tolower(*(argv[i]+1))) {
  65.             case 'p':  // protocol sequence
  66.                 pszProtocolSequence = argv[++i];
  67.                 break;
  68.             case 'e':
  69.                 pszEndpoint = argv[++i];
  70.                 break;
  71.             case 'm':
  72.                 cMaxCalls = (unsigned int) atoi(argv[++i]);
  73.                 break;
  74.             case 'n':
  75.                 cMinCalls = (unsigned int) atoi(argv[++i]);
  76.                 break;
  77.             case 'f':
  78.                 fDontWait = (unsigned int) atoi(argv[++i]);
  79.                 break;
  80.             case 'h':
  81.             case '?':
  82.             default:
  83.                 Usage(argv[0]);
  84.             }
  85.         }
  86.         else
  87.             Usage(argv[0]);
  88.     }
  89.  
  90.     status = RpcServerUseProtseqEp(pszProtocolSequence,
  91.                                    cMaxCalls,
  92.                                    pszEndpoint,
  93.                                    pszSecurity);  // Security descriptor
  94.     printf("RpcServerUseProtseqEp returned 0x%x\n", status);
  95.     if (status) {
  96.         exit(status);
  97.     }
  98.  
  99.     status = RpcServerRegisterIf(hello_ServerIfHandle,  // interface to register
  100.                                  NULL,   // MgrTypeUuid
  101.                                  NULL);  // MgrEpv; null means use default
  102.     printf("RpcServerRegisterIf returned 0x%x\n", status);
  103.     if (status) {
  104.         exit(status);
  105.     }
  106.  
  107.     printf("Calling RpcServerListen\n");
  108.     status = RpcServerListen(cMinCalls,
  109.                              cMaxCalls,
  110.                              fDontWait);
  111.     printf("RpcServerListen returned: 0x%x\n", status);
  112.     if (status) {
  113.         exit(status);
  114.     }
  115.  
  116.     if (fDontWait) {
  117.         printf("Calling RpcMgmtWaitServerListen\n");
  118.         status = RpcMgmtWaitServerListen();  // wait operation
  119.         printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
  120.         if (status) {
  121.             exit(status);
  122.         }
  123.     }
  124.  
  125. }  // end main()
  126.  
  127.  
  128. /*********************************************************************/
  129. /*                MIDL allocate and free                             */
  130. /*********************************************************************/
  131.  
  132. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  133. {
  134.     return(malloc(len));
  135. }
  136.  
  137. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  138. {
  139.     free(ptr);
  140. }
  141.  
  142. /* end file hellos.c */
  143.