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 / data / dunion / dunions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.4 KB  |  139 lines

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