|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
3: Copyright Microsoft Corp. 1992
4: Hello Example
5:
6: FILE: helloc.c
7: USAGE: client -n network_address
8: -p protocol_sequence
9: -e endpoint
10: -o options
1.1.1.2 ! root 11: -s string_displayed_on_server
1.1 root 12:
13: PURPOSE: Client side of RPC distributed application
14: FUNCTIONS: main() - binds to server and calls remote procedure
15: COMMENTS:
16: This distributed application prints a string such as "hello, world"
17: on the server. The client manages its connection to the server.
18: The client uses the binding handle hello_IfHandle defined in the
19: file hello.h.
20:
21: ****************************************************************************/
22: #include <stdio.h>
23: #include <string.h>
24: #include <stdlib.h>
25: #include <rpc.h> // RPC API functions, types
26: #include "hello.h" // header file generated by MIDL compiler
27:
28: void Usage(char * pszProgramName)
29: {
30: fprintf(stderr, "Usage: %s\n", pszProgramName);
31: fprintf(stderr, " -p protocol_sequence\n");
32: fprintf(stderr, " -n network_address\n");
33: fprintf(stderr, " -e endpoint\n");
34: fprintf(stderr, " -o options\n");
35: fprintf(stderr, " -s string\n");
36: exit(1);
37: }
38:
1.1.1.2 ! root 39: void _CRTAPI1 main(int argc, char **argv)
1.1 root 40: {
41: RPC_STATUS status; // returned by RPC API function
1.1.1.2 ! root 42: unsigned char * pszUuid = NULL;
1.1 root 43: unsigned char * pszProtocolSequence = "ncacn_np";
44: unsigned char * pszNetworkAddress = NULL;
45: unsigned char * pszEndpoint = "\\pipe\\hello";
46: unsigned char * pszOptions = NULL;
47: unsigned char * pszStringBinding = NULL;
48: unsigned char * pszString = "hello, world";
1.1.1.2 ! root 49: unsigned long ulCode;
1.1 root 50: int i;
51:
52: // allow the user to override settings with command line switches
53: for (i = 1; i < argc; i++) {
54: if ((*argv[i] == '-') || (*argv[i] == '/')) {
55: switch (tolower(*(argv[i]+1))) {
56: case 'p': // protocol sequence
57: pszProtocolSequence = argv[++i];
58: break;
59: case 'n': // network address
60: pszNetworkAddress = argv[++i];
61: break;
62: case 'e':
63: pszEndpoint = argv[++i];
64: break;
65: case 'o':
66: pszOptions = argv[++i];
67: break;
68: case 's':
69: pszString = argv[++i];
70: break;
71: case 'h':
72: case '?':
73: default:
74: Usage(argv[0]);
75: }
76: }
77: else
78: Usage(argv[0]);
79: }
80: /* Use a convenience function to concatenate the elements of */
81: /* the string binding into the proper sequence. */
82:
83: status = RpcStringBindingCompose(pszUuid,
84: pszProtocolSequence,
85: pszNetworkAddress,
86: pszEndpoint,
87: pszOptions,
88: &pszStringBinding);
89: printf("RpcStringBindingCompose returned 0x%x\n", status);
90: printf("pszStringBinding = %s\n", pszStringBinding);
91: if (status)
92: exit(2);
93:
94: /* Set the binding handle that will be used to bind to the server. */
95:
96: status = RpcBindingFromStringBinding(pszStringBinding,
97: &hello_IfHandle);
98: printf("RpcBindingFromStringBinding returned 0x%x\n", status);
99: if (status)
100: exit(2);
101:
102: printf("Calling the remote procedure 'HelloProc'\n");
103: printf(" print the string '%s' on the server\n", pszString);
104:
105: RpcTryExcept {
106: HelloProc(pszString); /* make call with user message */
107: printf("Calling the remote procedure 'Shutdown'\n");
108: Shutdown(); // shut down the server side
109: }
110: RpcExcept(1) {
1.1.1.2 ! root 111: ulCode = RpcExceptionCode();
! 112: printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode);
1.1 root 113: }
114: RpcEndExcept
115:
116: /* The calls to the remote procedures are complete. */
117: /* Free the string and the binding handle */
118:
119: status = RpcStringFree(&pszStringBinding); // remote calls done; unbind
120: printf("RpcStringFree returned 0x%x\n", status);
121: if (status)
122: exit(2);
123:
124: status = RpcBindingFree(&hello_IfHandle); // remote calls done; unbind
125: printf("RpcBindingFree returned 0x%x\n", status);
126: if (status)
127: exit(2);
128:
129: exit(0);
130:
131: }
132:
133: // ====================================================================
134: // MIDL allocate and free
135: // ====================================================================
136:
137:
138: void * MIDL_user_allocate(size_t len)
139: {
140: return(malloc(len));
141: }
142:
143: void MIDL_user_free(void * ptr)
144: {
145: free(ptr);
146: }
147:
148: /* end file helloc.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.