--- mstools/samples/rpc/data/inout/inoutc.c 2018/08/09 18:22:11 1.1.1.2 +++ mstools/samples/rpc/data/inout/inoutc.c 2018/08/09 18:24:26 1.1.1.3 @@ -1,27 +1,31 @@ /**************************************************************************** - Microsoft RPC Version 1.0 - Copyright Microsoft Corp. 1992 - InOut Example - - FILE: inoutc.c - USAGE: inoutc -n network_address - -p protocol_sequence - -e endpoint - -o options - -1 short_value_1 - -2 short_value_2 - -3 float_value_3 - - PURPOSE: Client side of RPC distributed application - FUNCTIONS: main() - binds to server and calls remote procedure - COMMENTS: + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + InOut Example + + FILE: inoutc.c + + USAGE: inoutc -n network_address + -p protocol_sequence + -e endpoint + -o options + -1 short_value_1 + -2 short_value_2 + -3 float_value_3 + + PURPOSE: Client side of RPC distributed application inout + + FUNCTIONS: main() - binds to server and calls remote procedure + + COMMENTS: This distributed application demonstrates in, out + parameters. ****************************************************************************/ -#include -#include + #include -#include // RPC API functions, types -#include "inout.h" // header file generated by MIDL compiler +#include +#include +#include "inout.h" // header file generated by MIDL compiler #define PURPOSE \ "This Microsoft RPC Version 1.0 sample program demonstrates\n\ @@ -48,70 +52,59 @@ void Usage(char * pszProgramName) exit(1); } -void * MIDL_user_allocate(size_t len) -{ - return(malloc(len)); -} - -void MIDL_user_free(void * ptr) -{ - free(ptr); -} - void _CRTAPI1 main(int argc, char **argv) { - RPC_STATUS status; // returned by RPC API function - unsigned char * pszUuid = NULL; + RPC_STATUS status; + unsigned char * pszUuid = NULL; unsigned char * pszProtocolSequence = "ncacn_np"; unsigned char * pszNetworkAddress = NULL; - unsigned char * pszEndpoint = "\\pipe\\inout"; + unsigned char * pszEndpoint = "\\pipe\\inout"; unsigned char * pszOptions = NULL; - unsigned char * pszStringBinding = NULL; + unsigned char * pszStringBinding = NULL; short s1 = 257; short s2 = 631; float f3 = (float) 0.406; - int i; - // allow the user to override settings with command line switches + /* allow the user to override settings with command line switches */ for (i = 1; i < argc; i++) { - if ((*argv[i] == '-') || (*argv[i] == '/')) { - switch (tolower(*(argv[i]+1))) { - case 'p': // protocol sequence - pszProtocolSequence = argv[++i]; - break; - case 'n': // network address - pszNetworkAddress = argv[++i]; - break; - case 'e': - pszEndpoint = argv[++i]; - break; - case 'o': - pszOptions = argv[++i]; - break; - case '1': - s1 = (short) atoi(argv[++i]); - break; - case '2': - s2 = (short) atoi(argv[++i]); - break; - case '3': - f3 = (float) atof(argv[++i]); - break; - case 'h': - case '?': - default: - Usage(argv[0]); - } - } - else - Usage(argv[0]); + if ((*argv[i] == '-') || (*argv[i] == '/')) { + switch (tolower(*(argv[i]+1))) { + case 'p': // protocol sequence + pszProtocolSequence = argv[++i]; + break; + case 'n': // network address + pszNetworkAddress = argv[++i]; + break; + case 'e': + pszEndpoint = argv[++i]; + break; + case 'o': + pszOptions = argv[++i]; + break; + case '1': + s1 = (short) atoi(argv[++i]); + break; + case '2': + s2 = (short) atoi(argv[++i]); + break; + case '3': + f3 = (float) atof(argv[++i]); + break; + case 'h': + case '?': + default: + Usage(argv[0]); + } + } + else + Usage(argv[0]); } + printf("%s", DESCRIPTION); -/* Use a convenience function to concatenate the elements of */ -/* the string binding into the proper sequence. */ - + /* Use a convenience function to concatenate the elements of */ + /* the string binding into the proper sequence. */ status = RpcStringBindingCompose(pszUuid, pszProtocolSequence, pszNetworkAddress, @@ -120,39 +113,59 @@ void _CRTAPI1 main(int argc, char **argv &pszStringBinding); printf("RpcStringBindingCompose returned 0x%x\n", status); printf("pszStringBinding = %s\n", pszStringBinding); - if (status) - exit(2); - -/* Set the binding handle that will be used to bind to the server. */ + if (status) { + exit(status); + } + /* Set the binding handle that will be used to bind to the server. */ status = RpcBindingFromStringBinding(pszStringBinding, - &inout_IfHandle); + &inout_IfHandle); printf("RpcBindingFromStringBinding returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } printf("Calling the remote procedure 'InOutProc'\n"); - printf(" parameters = %d %d %0.3f\n", s1, s2, f3); + printf(" parameters = %d %d %0.3f\n", s1, s2, f3); - InOutProc(s1, &s2, &f3); // call the remote procedure + InOutProc(s1, &s2, &f3); // call the remote procedure printf("Returning from the remote procedure 'InOutProc'\n"); - printf(" parameters = %d %d %0.3f\n", s1, s2, f3); + printf(" parameters = %d %d %0.3f\n", s1, s2, f3); Shutdown(); -/* The call to the remote procedure is complete. Free the binding handle */ - - status = RpcBindingFree(&inout_IfHandle); // remote calls done; unbind + /* The call to the remote procedure is complete. */ + /* Free the string and binding handle. */ + status = RpcBindingFree(&inout_IfHandle); printf("RpcBindingFree returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } - status = RpcStringFree(&pszStringBinding); // free memory for string + status = RpcStringFree(&pszStringBinding); printf("RpcStringFree returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } exit(0); -} /* end inoutc.c */ +} // end main() + + +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ + +void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) +{ + return(malloc(len)); +} + +void __RPC_API midl_user_free(void __RPC_FAR * ptr) +{ + free(ptr); +} + +/* end file inoutc.c */