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 / whello / whellos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  4.6 KB  |  143 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                           whello Example
  5.  
  6.      FILE:      whellos.c
  7.  
  8.      USAGE:     whellos  -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 whello
  15.  
  16.      FUNCTIONS:  main() - registers server as RPC server
  17.  
  18.      COMMENTS:   Windows version of the "Hello, World" example.
  19.  
  20.                  Windows can have several copies of your application
  21.                  running at the same time.  The variable hInst keeps
  22.                  track of which instance the application is so that
  23.                  processing will be to the correct window.
  24.  
  25. ****************************************************************************/
  26.  
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <ctype.h>
  30. #include "whello.h"    // header file generated by MIDL compiler
  31.  
  32. #define PURPOSE \
  33. "This Microsoft RPC Version 2.0 sample program demonstrates\n\
  34. the use of the [string] attribute. For more information\n\
  35. about the attributes and the RPC API functions, see the\n\
  36. RPC programming guide and reference.\n\n"
  37.  
  38. void Usage(char * pszProgramName)
  39. {
  40.     fprintf(stderr, "%s", PURPOSE);
  41.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  42.     fprintf(stderr, " -p protocol_sequence\n");
  43.     fprintf(stderr, " -e endpoint\n");
  44.     fprintf(stderr, " -m maxcalls\n");
  45.     fprintf(stderr, " -n mincalls\n");
  46.     fprintf(stderr, " -f flag_wait_op\n");
  47.     exit(1);
  48. }
  49.  
  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\\whello";
  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(whello_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_API midl_user_allocate(size_t len)
  133. {
  134.     return(malloc(len));
  135. }
  136.  
  137. void __RPC_API midl_user_free(void __RPC_FAR * ptr)
  138. {
  139.     free(ptr);
  140. }
  141.  
  142. /* end whellos.c */
  143.