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 / handles / auto / autoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  2.8 KB  |  100 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                          Auto Example
  5.  
  6.     FILE:       autoc.c
  7.  
  8.     USAGE:      autoc
  9.  
  10.     PURPOSE:    Client side of RPC distributed application
  11.  
  12.     FUNCTIONS:  main() - binds to server and calls remote procedure
  13.  
  14.     COMMENTS:   This distributed application (time stamp) is implemented
  15.                 using an auto handle.  The client side of the application
  16.                 does not care which server provides the time stamp; it
  17.                 merely wants to get the time from any available server.
  18.  
  19. ****************************************************************************/
  20.  
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <ctype.h>
  24. #include <time.h>
  25. #include "auto.h"    // header file generated by MIDL compiler
  26.  
  27. #define PURPOSE \
  28. "This Microsoft RPC Version 2.0 sample program demonstrates\n\
  29. the use of the [auto_handle] attribute. For more information\n\
  30. about attributes and RPC API functions, see the RPC programming\n\
  31. guide and reference.\n\n"
  32.  
  33. void Usage(char * pszProgramName)
  34. {
  35.     fprintf(stderr, "%s", PURPOSE);
  36.     fprintf(stderr, "Usage:  %s\n", pszProgramName);
  37.     exit(1);
  38. }
  39.  
  40. void _CRTAPI1 main(int argc, char **argv)
  41. {
  42.     time_t t1;
  43.     time_t t2;
  44.     char * pszTime;
  45.     int i;
  46.  
  47.     /* allow the user to override settings with command line switches */
  48.     for (i = 1; i < argc; i++) {
  49.         if ((*argv[i] == '-') || (*argv[i] == '/')) {
  50.             switch (tolower(*(argv[i]+1))) {
  51.             case 'h':
  52.             case '?':
  53.             default:
  54.                 Usage(argv[0]);
  55.             }
  56.         }
  57.         else
  58.             Usage(argv[0]);
  59.     }
  60.  
  61.     RpcTryExcept {
  62.         GetTime(&t1);  // GetTime is a remote procedure
  63.         GetTime(&t2);
  64.  
  65.         pszTime = ctime(&t1);
  66.         printf("time 1= %s\n", pszTime);
  67.  
  68.         pszTime = ctime(&t2);
  69.         printf("time 2= %s\n", pszTime);
  70.  
  71.         Shutdown();    // Shutdown is a remote procedure
  72.     }
  73.     RpcExcept(1) {
  74.         printf("The RPC runtime library raised an exception.\n");
  75.         printf("Please verify that the server application and \n");
  76.         printf("the locator service have been started.");
  77.     }
  78.     RpcEndExcept
  79.  
  80.     exit(0);
  81.  
  82. }  // end main()
  83.  
  84.  
  85. /*********************************************************************/
  86. /*                 MIDL allocate and free                            */
  87. /*********************************************************************/
  88.  
  89. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  90. {
  91.     return(malloc(len));
  92. }
  93.  
  94. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  95. {
  96.     free(ptr);
  97. }
  98.  
  99. /* end file autoc.c */
  100.