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 / dunionp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-11  |  2.2 KB  |  83 lines

  1. /****************************************************************************
  2.                    Microsoft RPC Version 2.0
  3.            Copyright Microsoft Corp. 1992, 1993, 1994- 1996
  4.                    Discriminated Union Example
  5.  
  6.     FILE:       unionp.c
  7.  
  8.     PURPOSE:    Remote procedures that are linked with the server
  9.                 side of RPC distributed application
  10.  
  11.     FUNCTIONS:  UnionParamProc()  - union, discriminant are parameters
  12.                 UnionStructProc() - union, discriminant in structure
  13.  
  14.     COMMENTS:   This distributed application illustrates distriminated
  15.                 union.
  16.  
  17. ****************************************************************************/
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include "dunion.h"    // header file generated by MIDL compiler
  22.  
  23.  
  24. void UnionParamProc(DISCRIM_UNION_PARAM_TYPE *up,
  25.                     short                    sDiscrim)
  26. {
  27.     printf("sDiscrim = %d, data = ", sDiscrim);
  28.     switch(sDiscrim) {
  29.     case 0:
  30.         printf("short %d\n", up->sVal);
  31.         break;
  32.     case 1:
  33.         printf("float %f\n", up->fVal);
  34.         break;
  35.     case 2:
  36.         printf("char %c\n", up->chVal);
  37.         break;
  38.     default:
  39.         printf("invalid\n");
  40.         break;
  41.     }
  42. }
  43.  
  44. void UnionStructProc(DISCRIM_UNION_STRUCT_TYPE *u)
  45. {
  46.     printf("sDiscrim = %d, data = ", u->sDiscrim);
  47.     switch(u->sDiscrim) {
  48.     case 0:
  49.         printf("short %d\n", u->u.sVal);
  50.         break;
  51.     case 1:
  52.         printf("float %f\n", u->u.fVal);
  53.         break;
  54.     case 2:
  55.         printf("char %c\n", u->u.chVal);
  56.         break;
  57.     default:
  58.         printf("invalid\n");
  59.         break;
  60.     }
  61. }
  62.  
  63. void Shutdown(void)
  64. {
  65.     RPC_STATUS status;
  66.  
  67.     printf("Calling RpcMgmtStopServerListening\n");
  68.     status = RpcMgmtStopServerListening(NULL);
  69.     printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
  70.     if (status) {
  71.         exit(status);
  72.     }
  73.  
  74.     printf("Calling RpcServerUnregisterIf\n");
  75.     status = RpcServerUnregisterIf(NULL, NULL, FALSE);
  76.     printf("RpcServerUnregisterIf returned 0x%x\n", status);
  77.     if (status) {
  78.         exit(status);
  79.     }
  80. }
  81.  
  82. /* end file dunionp.c */
  83.