|
|
1.1 root 1: /****************************************************************************
2: Microsoft RPC Version 1.0
3: Copyright Microsoft Corp. 1992
4: nhello Example
5:
6: FILE: nhelloc.c
7:
8: USAGE: nhelloc -s string
9: -n name_service_entry_name
10: -t name_syntax_type
11:
12: PURPOSE: Client side of RPC distributed application
13:
14: FUNCTIONS: main() - binds to server and calls remote procedure
15:
16: COMMENTS:
17:
18: ****************************************************************************/
19:
20: #include <stdlib.h>
21: #include <stdio.h>
22: #include <ctype.h>
23: #include "nhello.h" // header file generated by MIDL compiler
24:
25: #define PURPOSE \
26: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
27: the use of the name service. For more information about these\n\
28: RPC API functions, see the RPC programming guide and reference.\n\n"
29:
30: void Usage(char * pszProgramName)
31: {
32: fprintf(stderr, "%s", PURPOSE);
33: fprintf(stderr, "Usage: %s\n", pszProgramName);
34: fprintf(stderr, " -s string\n");
35: fprintf(stderr, " -n name_service_entry_name\n");
36: fprintf(stderr, " -t name_syntax_type\n");
37: exit(1);
38: }
39:
40: void _CRTAPI1 main(int argc, char **argv)
41: {
42: unsigned char * pszString = "hello, world";
43: unsigned char * pszEntryName = "/.:/nhello_sample";
44: RPC_NS_HANDLE hnsHello;
45: RPC_BINDING_HANDLE hHello;
46: unsigned long fNameSyntaxType = RPC_C_NS_SYNTAX_DEFAULT;
47: RPC_STATUS status;
48: unsigned long ulCode;
49: short fContinue = TRUE;
50: short 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 'n':
57: pszEntryName = argv[++i];
58: break;
59: case 't':
60: fNameSyntaxType = (unsigned int) atoi(argv[++i]);
61: break;
62: case 's':
63: pszString = argv[++i];
64: break;
65: case 'h':
66: case '?':
67: default:
68: Usage(argv[0]);
69: }
70: }
71: else
72: Usage(argv[0]);
73: }
74:
75: RpcTryExcept {
76: status = RpcNsBindingImportBegin(fNameSyntaxType,
77: pszEntryName,
78: nhello_ClientIfHandle,
79: NULL,
80: &hnsHello);
81: printf("RpcNsBindingImportBegin returned 0x%x\n", status);
82: }
83: RpcExcept(1) {
84: ulCode = RpcExceptionCode();
85: printf("RPC Runtime raised exception 0x%x\n", ulCode);
86: exit(1);
87: }
88: RpcEndExcept
89:
90: /* The loop is present because the name service may contain "stale" */
91: /* and unusable binding handlers. This is part of the DCE design. */
92: do {
93: status = RpcNsBindingImportNext(hnsHello,
94: &hHello);
95: printf("RpcNsBindingImportNext returned 0x%x\n", status);
96: if (status == RPC_S_NO_MORE_BINDINGS)
97: exit(status);
98:
99: if (status != RPC_S_OK)
100: continue;
101:
102: RpcTryExcept {
103: printf("Calling remote procedure HelloProc with string %s\n",
104: pszString);
105: HelloProc(hHello, pszString);
106: fContinue = FALSE;
107: }
108: RpcExcept(1) {
109: fContinue = TRUE;
110: }
111: RpcEndExcept
112:
113: } while (fContinue == TRUE);
114:
115: status = RpcNsBindingImportDone(&hnsHello);
116: printf("RpcNsBindingImportDone returned 0x%x\n", status);
117:
118: RpcTryExcept {
119: Shutdown(hHello); // Shutdown is a remote procedure
120: }
121: RpcExcept(1) {
122: ulCode = RpcExceptionCode();
123: printf("RPC runtime raised exception 0x%x\n", ulCode);
124: }
125: RpcEndExcept
126:
127: status = RpcBindingFree(&hHello);
128: printf("RpcBindingFree returned 0x%x\n", status);
129:
130: exit(0);
131:
132: } // end main()
133:
134:
135: /*********************************************************************/
136: /* MIDL allocate and free */
137: /*********************************************************************/
138:
139: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
140: {
141: return(malloc(len));
142: }
143:
144: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
145: {
146: free(ptr);
147: }
148:
149: /* end file nhelloc.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.