|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
3: Copyright Microsoft Corp. 1992
1.1.1.2 ! root 4: hello Example
1.1 root 5:
6: FILE: hellos.c
1.1.1.2 ! root 7: USAGE: hellos -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 hello
1.1.1.2 ! root 15: FUNCTIONS: main() - registers server as RPC server
! 16:
! 17: COMMENTS: This sample program generates a linked list to
! 18: demonstrate how the list can be transmitted over
! 19: the network more efficiently as a sized array.
! 20: The pointers are rebuilt on the server side.
! 21:
! 22: The [transmit_as] attribute (used in the typedef of
! 23: DOUBLE_LINK_TYPE in the file hello.IDL) requires the
! 24: four user-supplied functions whose names start with
! 25: the name of the presented type, DOUBLE_LINK_TYPE.
! 26:
! 27: The [in, out] attributes applied to remote procedure
! 28: parameters require the two user-supplied functions
! 29: MIDL_user_allocate and MIDL_user_free.
! 30:
! 31: The other functions are utilities that are used to
! 32: build or display the data structures.
1.1 root 33: ****************************************************************************/
34: #include <stdlib.h>
35: #include <windows.h>
36: #include <string.h>
37: #include <stdio.h>
38: #include <ctype.h>
39: #include <rpc.h> // RPC data structures and APIs
40: #include "hello.h" // header file generated by MIDL compiler
41:
1.1.1.2 ! root 42: #define PURPOSE \
! 43: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
! 44: the use of the [string] attribute. For more information\n\
! 45: about the attributes and the RPC API functions, see the\n\
! 46: RPC programming guide and reference.\n\n"
! 47:
1.1 root 48: void Usage(char * pszProgramName)
49: {
1.1.1.2 ! root 50: fprintf(stderr, "%s", PURPOSE);
1.1 root 51: fprintf(stderr, "Usage: %s\n", pszProgramName);
52: fprintf(stderr, " -p protocol_sequence\n");
53: fprintf(stderr, " -e endpoint\n");
1.1.1.2 ! root 54: fprintf(stderr, " -m maxcalls\n");
! 55: fprintf(stderr, " -n mincalls\n");
! 56: fprintf(stderr, " -f flag_wait_op\n");
! 57: fprintf(stderr, " -s security_descriptor\n");
1.1 root 58: exit(1);
59: }
60:
1.1.1.2 ! root 61: /* main: register the interface, start listening for clients */
! 62: void _CRTAPI1 main(int argc, char * argv[])
1.1 root 63: {
64: RPC_STATUS status;
65: unsigned char * pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root 66: unsigned char * pszSecurity = NULL;
1.1 root 67: unsigned char * pszEndpoint = "\\pipe\\hello";
1.1.1.2 ! root 68: unsigned int cMinCalls = 1;
! 69: unsigned int cMaxCalls = 20;
! 70: unsigned int fDontWait = FALSE;
1.1 root 71: int i;
72:
73: // allow the user to override settings with command line switches
74: for (i = 1; i < argc; i++) {
75: if ((*argv[i] == '-') || (*argv[i] == '/')) {
76: switch (tolower(*(argv[i]+1))) {
77: case 'p': // protocol sequence
78: pszProtocolSequence = argv[++i];
79: break;
80: case 'e':
81: pszEndpoint = argv[++i];
82: break;
1.1.1.2 ! root 83: case 'm':
! 84: cMaxCalls = (unsigned int) atoi(argv[++i]);
! 85: break;
! 86: case 'n':
! 87: cMinCalls = (unsigned int) atoi(argv[++i]);
1.1 root 88: break;
1.1.1.2 ! root 89: case 'f':
! 90: fDontWait = (unsigned int) atoi(argv[++i]);
! 91: break;
! 92: case 's':
! 93: pszSecurity = argv[++i];
1.1 root 94: break;
95: case 'h':
96: case '?':
97: default:
98: Usage(argv[0]);
99: }
100: }
101: else
102: Usage(argv[0]);
103: }
104:
105: status = RpcServerUseProtseqEp(pszProtocolSequence,
1.1.1.2 ! root 106: cMaxCalls, // max concurrent calls
1.1 root 107: pszEndpoint,
1.1.1.2 ! root 108: pszSecurity); // Security descriptor
1.1 root 109: printf("RpcServerUseProtseqEp returned 0x%x\n", status);
110: if (status) {
1.1.1.2 ! root 111: exit(status);
1.1 root 112: }
113:
1.1.1.2 ! root 114: status = RpcServerRegisterIf(
! 115: hello_ServerIfHandle, // interface to register
! 116: NULL, // MgrTypeUuid
! 117: NULL); // MgrEpv; null means use default
1.1 root 118: printf("RpcServerRegisterIf returned 0x%x\n", status);
119: if (status) {
1.1.1.2 ! root 120: exit(status);
1.1 root 121: }
122:
123: printf("Calling RpcServerListen\n");
1.1.1.2 ! root 124: status = RpcServerListen(cMinCalls,
! 125: cMaxCalls,
! 126: fDontWait);
1.1 root 127: printf("RpcServerListen returned: 0x%x\n", status);
128: if (status) {
1.1.1.2 ! root 129: exit(status);
! 130: }
! 131:
! 132: if (fDontWait) {
! 133: printf("Calling RpcMgmtWaitServerListen\n");
! 134: status = RpcMgmtWaitServerListen(); // wait operation
! 135: printf("RpcMgmtWaitServerListen returned: 0x%x\n", status);
! 136: if (status) {
! 137: exit(status);
! 138: }
1.1 root 139: }
140:
141: } /* end main() */
142:
143: // ====================================================================
144: // MIDL allocate and free
145: // ====================================================================
146:
147: void * MIDL_user_allocate(size_t len)
148: {
149: return(malloc(len));
150: }
151:
152: void MIDL_user_free(void * ptr)
153: {
154: free(ptr);
155: }
156:
157: /* end hellos.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.