|
|
1.1 root 1: /**************************************************************************** 1.1.1.3 ! root 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: Discriminated Union Example 1.1.1.2 root 5: 1.1.1.3 ! root 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. 1.1.1.2 root 20: 1.1 root 21: ****************************************************************************/ 1.1.1.3 ! root 22: 1.1 root 23: #include <stdlib.h> 24: #include <stdio.h> 25: #include <ctype.h> 26: #include "dunion.h" // header file generated by MIDL compiler 27: 1.1.1.2 root 28: #define PURPOSE \ 29: "This Microsoft RPC Version 1.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: 1.1 root 34: void Usage(char * pszProgramName) 35: { 1.1.1.2 root 36: fprintf(stderr, "%s", PURPOSE); 1.1 root 37: fprintf(stderr, "Usage: %s\n", pszProgramName); 38: fprintf(stderr, " -p protocol_sequence\n"); 39: fprintf(stderr, " -e endpoint\n"); 1.1.1.2 root 40: fprintf(stderr, " -m maxcalls\n"); 41: fprintf(stderr, " -n mincalls\n"); 42: fprintf(stderr, " -f flag_wait_op\n"); 1.1 root 43: exit(1); 44: } 45: 1.1.1.2 root 46: void _CRTAPI1 main(int argc, char * argv[]) 1.1 root 47: { 48: RPC_STATUS status; 49: unsigned char * pszProtocolSequence = "ncacn_np"; 1.1.1.3 ! root 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; 1.1 root 55: int i; 56: 1.1.1.3 ! root 57: /* allow the user to override settings with command line switches */ 1.1 root 58: for (i = 1; i < argc; i++) { 1.1.1.3 ! root 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: /*********************************************************************/ 1.1 root 127: 1.1.1.3 ! root 128: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) 1.1 root 129: { 130: return(malloc(len)); 131: } 132: 1.1.1.3 ! root 133: void __RPC_API midl_user_free(void __RPC_FAR * ptr) 1.1 root 134: { 135: free(ptr); 136: } 137: 1.1.1.3 ! root 138: /* end file dunions.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.