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 / doctor / doctors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.3 KB  |  137 lines

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