|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
1.1.1.2 ! root 3: Copyright Microsoft Corp. 1992
! 4: dunion Example
1.1 root 5:
6: FILE: dunions.c
1.1.1.2 ! root 7: USAGE: dunions -p protocol_sequence
! 8: -e endpoint
! 9: -m max calls
! 10: -n min calls
! 11: -s security descriptor
! 12: -f flag for RpcServerListen
! 13:
1.1 root 14: PURPOSE: Server side of RPC distributed application dunion
1.1.1.2 ! root 15: FUNCTIONS: main() - registers server as RPC server
! 16:
1.1 root 17: COMMENTS:
18: ****************************************************************************/
19: #include <stdlib.h>
20: #include <windows.h>
21: #include <string.h>
22: #include <stdio.h>
23: #include <ctype.h>
24: #include <rpc.h> // RPC data structures and APIs
25: #include "dunion.h" // header file generated by MIDL compiler
26:
1.1.1.2 ! root 27: #define PURPOSE \
! 28: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
! 29: two ways to specify a discriminated union. For more information\n\
! 30: about the attributes and the RPC API functions, see the\n\
! 31: RPC programming guide and reference.\n\n"
! 32:
1.1 root 33: void Usage(char * pszProgramName)
34: {
1.1.1.2 ! root 35: fprintf(stderr, "%s", PURPOSE);
1.1 root 36: fprintf(stderr, "Usage: %s\n", pszProgramName);
37: fprintf(stderr, " -p protocol_sequence\n");
38: fprintf(stderr, " -e endpoint\n");
1.1.1.2 ! root 39: fprintf(stderr, " -m maxcalls\n");
! 40: fprintf(stderr, " -n mincalls\n");
! 41: fprintf(stderr, " -f flag_wait_op\n");
! 42: fprintf(stderr, " -s security_descriptor\n");
1.1 root 43: exit(1);
44: }
45:
1.1.1.2 ! root 46: /* main: register the interface, start listening for clients */
! 47: void _CRTAPI1 main(int argc, char * argv[])
1.1 root 48: {
49: RPC_STATUS status;
50: unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root 51: unsigned char * pszSecurity = NULL;
1.1 root 52: unsigned char * pszEndpoint = "\\pipe\\dunion";
1.1.1.2 ! root 53: unsigned int cMinCalls = 1;
! 54: unsigned int cMaxCalls = 20;
! 55: unsigned int fDontWait = FALSE;
1.1 root 56: int i;
57:
58: // allow the user to override settings with command line switches
59: for (i = 1; i < argc; i++) {
60: if ((*argv[i] == '-') || (*argv[i] == '/')) {
61: switch (tolower(*(argv[i]+1))) {
62: case 'p': // protocol sequence
63: pszProtocolSequence = argv[++i];
64: break;
65: case 'e':
66: pszEndpoint = argv[++i];
67: break;
1.1.1.2 ! root 68: case 'm':
! 69: cMaxCalls = (unsigned int) atoi(argv[++i]);
! 70: break;
! 71: case 'n':
! 72: cMinCalls = (unsigned int) atoi(argv[++i]);
! 73: break;
! 74: case 'f':
! 75: fDontWait = (unsigned int) atoi(argv[++i]);
1.1 root 76: break;
1.1.1.2 ! root 77: case 's':
! 78: pszSecurity = argv[++i];
1.1 root 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,
1.1.1.2 ! root 91: cMaxCalls, // max concurrent calls
1.1 root 92: pszEndpoint,
1.1.1.2 ! root 93: pszSecurity); // Security descriptor
1.1 root 94: printf("RpcServerUseProtseqEp returned 0x%x\n", status);
95: if (status) {
1.1.1.2 ! root 96: exit(status);
1.1 root 97: }
98:
1.1.1.2 ! root 99: status = RpcServerRegisterIf(
! 100: dunion_ServerIfHandle, // interface to register
! 101: NULL, // MgrTypeUuid
! 102: NULL); // MgrEpv; null means use default
1.1 root 103: printf("RpcServerRegisterIf returned 0x%x\n", status);
104: if (status) {
1.1.1.2 ! root 105: exit(status);
1.1 root 106: }
107:
108: printf("Calling RpcServerListen\n");
1.1.1.2 ! root 109: status = RpcServerListen(cMinCalls,
! 110: cMaxCalls,
! 111: fDontWait);
1.1 root 112: printf("RpcServerListen returned: 0x%x\n", status);
113: if (status) {
1.1.1.2 ! root 114: exit(status);
! 115: }
! 116:
! 117: if (fDontWait) {
! 118: printf("Calling RpcMgmtWaitServerListen\n");
! 119: status = RpcMgmtWaitServerListen(); // wait operation
! 120: printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
! 121: if (status) {
! 122: exit(status);
! 123: }
1.1 root 124: }
125:
126: } /* end main() */
127:
128: // ====================================================================
129: // MIDL allocate and free
130: // ====================================================================
131:
132: void * MIDL_user_allocate(size_t len)
133: {
134: return(malloc(len));
135: }
136:
137: void MIDL_user_free(void * ptr)
138: {
139: free(ptr);
140: }
141:
142: /* end dunions.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.