--- mstools/samples/rpc/hello/helloc.c 2018/08/09 18:20:55 1.1.1.1 +++ mstools/samples/rpc/hello/helloc.c 2018/08/09 18:24:13 1.1.1.3 @@ -1,29 +1,32 @@ /**************************************************************************** - Microsoft RPC Version 1.0 - Copyright Microsoft Corp. 1992 - Hello Example - - FILE: helloc.c - USAGE: client -n network_address - -p protocol_sequence - -e endpoint - -o options - -u uuid - - PURPOSE: Client side of RPC distributed application - FUNCTIONS: main() - binds to server and calls remote procedure - COMMENTS: - This distributed application prints a string such as "hello, world" - on the server. The client manages its connection to the server. - The client uses the binding handle hello_IfHandle defined in the - file hello.h. + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + Hello Example + + FILE: helloc.c + + USAGE: helloc -n network_address + -p protocol_sequence + -e endpoint + -o options + -s string_displayed_on_server + + PURPOSE: Client side of RPC distributed application + + FUNCTIONS: main() - binds to server and calls remote procedure + + COMMENTS: This version of the distributed application that + prints "hello, world" (or other string) on the server + features a client that manages its connection to the + server. It uses the binding handle hello_IfHandle, + defined in the file hello.h. ****************************************************************************/ -#include -#include + #include -#include // RPC API functions, types -#include "hello.h" // header file generated by MIDL compiler +#include +#include +#include "hello.h" // header file generated by MIDL compiler void Usage(char * pszProgramName) { @@ -32,57 +35,54 @@ void Usage(char * pszProgramName) fprintf(stderr, " -n network_address\n"); fprintf(stderr, " -e endpoint\n"); fprintf(stderr, " -o options\n"); - fprintf(stderr, " -u uuid\n"); fprintf(stderr, " -s string\n"); exit(1); } -void main(int argc, char **argv) +void _CRTAPI1 main(int argc, char **argv) { - RPC_STATUS status; // returned by RPC API function - unsigned char * pszUuid = "12345678-1234-1234-1234-123456789ABC"; + RPC_STATUS status; + unsigned char * pszUuid = NULL; unsigned char * pszProtocolSequence = "ncacn_np"; unsigned char * pszNetworkAddress = NULL; - unsigned char * pszEndpoint = "\\pipe\\hello"; + unsigned char * pszEndpoint = "\\pipe\\hello"; unsigned char * pszOptions = NULL; - unsigned char * pszStringBinding = NULL; - unsigned char * pszString = "hello, world"; + unsigned char * pszStringBinding = NULL; + unsigned char * pszString = "hello, world"; + unsigned long ulCode; 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 'u': - pszUuid = argv[++i]; - break; - case 's': - pszString = 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': // endpoint + pszEndpoint = argv[++i]; + break; + case 'o': + pszOptions = argv[++i]; + break; + case 's': + pszString = argv[++i]; + break; + case 'h': + case '?': + default: + Usage(argv[0]); + } + } + else + Usage(argv[0]); } -/* 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, @@ -91,59 +91,61 @@ void 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, - &hello_IfHandle); + &hello_IfHandle); printf("RpcBindingFromStringBinding returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } printf("Calling the remote procedure 'HelloProc'\n"); - printf(" print the string '%s' on the server\n", pszString); + printf("Print the string '%s' on the server\n", pszString); RpcTryExcept { - HelloProc(pszString); /* make call with user message */ - printf("Calling the remote procedure 'Shutdown'\n"); - Shutdown(); // shut down the server side + HelloProc(pszString); // make call with user message + printf("Calling the remote procedure 'Shutdown'\n"); + Shutdown(); // shut down the server side } RpcExcept(1) { - printf("Runtime library reported an exception\n"); + ulCode = RpcExceptionCode(); + printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode); } RpcEndExcept -/* The calls to the remote procedures are complete. */ -/* Free the string and the binding handle */ - - status = RpcStringFree(&pszStringBinding); // remote calls done; unbind + /* The calls to the remote procedures are complete. */ + /* Free the string and the binding handle */ + status = RpcStringFree(&pszStringBinding); // remote calls done; unbind printf("RpcStringFree returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } status = RpcBindingFree(&hello_IfHandle); // remote calls done; unbind printf("RpcBindingFree returned 0x%x\n", status); - if (status) - exit(2); - + if (status) { + exit(status); + } exit(0); -} +} // end main() -// ==================================================================== -// MIDL allocate and free -// ==================================================================== +/*********************************************************************/ +/* MIDL allocate and free */ +/*********************************************************************/ -void * MIDL_user_allocate(size_t len) +void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) { return(malloc(len)); } -void MIDL_user_free(void * ptr) +void __RPC_API midl_user_free(void __RPC_FAR * ptr) { free(ptr); }