|
|
1.1 root 1: /**************************************************************************** 1.1.1.3 ! root 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: InOut Example ! 5: ! 6: FILE: inoutc.c ! 7: ! 8: USAGE: inoutc -n network_address ! 9: -p protocol_sequence ! 10: -e endpoint ! 11: -o options ! 12: -1 short_value_1 ! 13: -2 short_value_2 ! 14: -3 float_value_3 ! 15: ! 16: PURPOSE: Client side of RPC distributed application inout ! 17: ! 18: FUNCTIONS: main() - binds to server and calls remote procedure ! 19: ! 20: COMMENTS: This distributed application demonstrates in, out ! 21: parameters. 1.1 root 22: 23: ****************************************************************************/ 1.1.1.3 ! root 24: 1.1 root 25: #include <stdlib.h> 1.1.1.3 ! root 26: #include <stdio.h> ! 27: #include <ctype.h> ! 28: #include "inout.h" // header file generated by MIDL compiler 1.1 root 29: 30: #define PURPOSE \ 31: "This Microsoft RPC Version 1.0 sample program demonstrates\n\ 32: use of the [in], [out], and [in, out] attributes. For more\n\ 33: information about attributes and RPC API functions, see the\n\ 34: Microsoft RPC programming guide and reference.\n\n" 35: 36: #define DESCRIPTION \ 37: "One [in], one [out], and one [in,out] parameter are defined\n\ 38: for the function InOutProc(). This program displays the values\n\ 39: of these parameters before and after the remote procedure call.\n\n" 40: 41: void Usage(char * pszProgramName) 42: { 43: fprintf(stderr, "%s", PURPOSE); 44: fprintf(stderr, "Usage: %s\n", pszProgramName); 45: fprintf(stderr, " -p protocol_sequence\n"); 46: fprintf(stderr, " -n network_address\n"); 47: fprintf(stderr, " -e endpoint\n"); 48: fprintf(stderr, " -o options\n"); 49: fprintf(stderr, " -1 parameter_1\n"); 50: fprintf(stderr, " -2 parameter_2\n"); 51: fprintf(stderr, " -3 parameter_3\n"); 52: exit(1); 53: } 54: 1.1.1.2 root 55: void _CRTAPI1 main(int argc, char **argv) 1.1 root 56: { 1.1.1.3 ! root 57: RPC_STATUS status; ! 58: unsigned char * pszUuid = NULL; 1.1 root 59: unsigned char * pszProtocolSequence = "ncacn_np"; 60: unsigned char * pszNetworkAddress = NULL; 1.1.1.3 ! root 61: unsigned char * pszEndpoint = "\\pipe\\inout"; 1.1 root 62: unsigned char * pszOptions = NULL; 1.1.1.3 ! root 63: unsigned char * pszStringBinding = NULL; 1.1 root 64: short s1 = 257; 65: short s2 = 631; 66: float f3 = (float) 0.406; 67: int i; 68: 1.1.1.3 ! root 69: /* allow the user to override settings with command line switches */ 1.1 root 70: for (i = 1; i < argc; i++) { 1.1.1.3 ! root 71: if ((*argv[i] == '-') || (*argv[i] == '/')) { ! 72: switch (tolower(*(argv[i]+1))) { ! 73: case 'p': // protocol sequence ! 74: pszProtocolSequence = argv[++i]; ! 75: break; ! 76: case 'n': // network address ! 77: pszNetworkAddress = argv[++i]; ! 78: break; ! 79: case 'e': ! 80: pszEndpoint = argv[++i]; ! 81: break; ! 82: case 'o': ! 83: pszOptions = argv[++i]; ! 84: break; ! 85: case '1': ! 86: s1 = (short) atoi(argv[++i]); ! 87: break; ! 88: case '2': ! 89: s2 = (short) atoi(argv[++i]); ! 90: break; ! 91: case '3': ! 92: f3 = (float) atof(argv[++i]); ! 93: break; ! 94: case 'h': ! 95: case '?': ! 96: default: ! 97: Usage(argv[0]); ! 98: } ! 99: } ! 100: else ! 101: Usage(argv[0]); 1.1 root 102: } 1.1.1.3 ! root 103: 1.1 root 104: printf("%s", DESCRIPTION); 105: 1.1.1.3 ! root 106: /* Use a convenience function to concatenate the elements of */ ! 107: /* the string binding into the proper sequence. */ 1.1 root 108: status = RpcStringBindingCompose(pszUuid, 109: pszProtocolSequence, 110: pszNetworkAddress, 111: pszEndpoint, 112: pszOptions, 113: &pszStringBinding); 114: printf("RpcStringBindingCompose returned 0x%x\n", status); 115: printf("pszStringBinding = %s\n", pszStringBinding); 1.1.1.3 ! root 116: if (status) { ! 117: exit(status); ! 118: } 1.1 root 119: 1.1.1.3 ! root 120: /* Set the binding handle that will be used to bind to the server. */ 1.1 root 121: status = RpcBindingFromStringBinding(pszStringBinding, 1.1.1.3 ! root 122: &inout_IfHandle); 1.1 root 123: printf("RpcBindingFromStringBinding returned 0x%x\n", status); 1.1.1.3 ! root 124: if (status) { ! 125: exit(status); ! 126: } 1.1 root 127: 128: printf("Calling the remote procedure 'InOutProc'\n"); 1.1.1.3 ! root 129: printf(" parameters = %d %d %0.3f\n", s1, s2, f3); 1.1 root 130: 1.1.1.3 ! root 131: InOutProc(s1, &s2, &f3); // call the remote procedure 1.1 root 132: 133: printf("Returning from the remote procedure 'InOutProc'\n"); 1.1.1.3 ! root 134: printf(" parameters = %d %d %0.3f\n", s1, s2, f3); 1.1 root 135: 136: Shutdown(); 137: 1.1.1.3 ! root 138: /* The call to the remote procedure is complete. */ ! 139: /* Free the string and binding handle. */ ! 140: status = RpcBindingFree(&inout_IfHandle); 1.1 root 141: printf("RpcBindingFree returned 0x%x\n", status); 1.1.1.3 ! root 142: if (status) { ! 143: exit(status); ! 144: } 1.1 root 145: 1.1.1.3 ! root 146: status = RpcStringFree(&pszStringBinding); 1.1 root 147: printf("RpcStringFree returned 0x%x\n", status); 1.1.1.3 ! root 148: if (status) { ! 149: exit(status); ! 150: } 1.1 root 151: 152: exit(0); 153: 1.1.1.3 ! root 154: } // end main() ! 155: ! 156: ! 157: /*********************************************************************/ ! 158: /* MIDL allocate and free */ ! 159: /*********************************************************************/ ! 160: ! 161: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) ! 162: { ! 163: return(malloc(len)); ! 164: } ! 165: ! 166: void __RPC_API midl_user_free(void __RPC_FAR * ptr) ! 167: { ! 168: free(ptr); ! 169: } ! 170: ! 171: /* end file inoutc.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.