--- mstools/samples/rpc/handles/usrdef/usrdefc.c 2018/08/09 18:20:56 1.1 +++ mstools/samples/rpc/handles/usrdef/usrdefc.c 2018/08/09 18:24:18 1.1.1.3 @@ -1,26 +1,27 @@ /**************************************************************************** - Microsoft RPC Version 1.0 - Copyright Microsoft Corp. 1992 - usrdef Example - - FILE: usrdefc.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: + Microsoft RPC Version 1.0 + Copyright Microsoft Corp. 1992 + usrdef Example + + FILE: usrdefc.c + + USAGE: usrdefc -n network_address + -p protocol_sequence + -e endpoint + -o options + + PURPOSE: Client side of RPC distributed application + + FUNCTIONS: main() - binds to server and calls remote procedure + + COMMENTS: This distributed application uses a user-defined handle. + ****************************************************************************/ -#include -#include -#include -#include // RPC API functions, types -#include "usrdef.h" // header file generated by MIDL compiler -unsigned char * pszStringBinding; +#include +#include +#include +#include "usrdef.h" // header file generated by MIDL compiler void Usage(char * pszProgramName) { @@ -29,118 +30,125 @@ 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) { -int i; -DATA_HANDLE_TYPE dhBinding; -unsigned char * pszString = "hello, world"; - - dhBinding.pszProtocolSequence = "ncacn_np"; - dhBinding.pszUuid = "12345678-1234-1234-1234-123456789ABC"; - dhBinding.pszEndpoint = "\\pipe\\usrdef"; - dhBinding.pszNetworkAddress = NULL; - dhBinding.pszOptions = NULL; + int i; + DATA_HANDLE_TYPE dhBinding; + unsigned char * pszString = "hello, world"; + + dhBinding = (DATA_HANDLE_TYPE) midl_user_allocate(sizeof(DATA_TYPE)); + dhBinding->pszProtocolSequence = "ncacn_np"; + dhBinding->pszUuid = NULL; + dhBinding->pszEndpoint = "\\pipe\\usrdef"; + dhBinding->pszNetworkAddress = NULL; + dhBinding->pszOptions = NULL; - // 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 - dhBinding.pszProtocolSequence = argv[++i]; - break; - case 'n': // network address - dhBinding.pszNetworkAddress = argv[++i]; - break; - case 'e': - dhBinding.pszEndpoint = argv[++i]; - break; - case 'o': - dhBinding.pszOptions = argv[++i]; - break; - case 'u': - dhBinding.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 + dhBinding->pszProtocolSequence = argv[++i]; + break; + case 'n': // network address + dhBinding->pszNetworkAddress = argv[++i]; + break; + case 'e': + dhBinding->pszEndpoint = argv[++i]; + break; + case 'o': + dhBinding->pszOptions = argv[++i]; + break; + case 's': + pszString = argv[++i]; + break; + case 'h': + case '?': + default: + Usage(argv[0]); + } + } + else + Usage(argv[0]); } printf("Calling the remote procedure 'UsrdefProc'\n"); - - UsrdefProc(dhBinding, pszString); // call the remote procedure + UsrdefProc(dhBinding, pszString); // call the remote procedure printf("Calling the remote procedure 'Shutdown'\n"); - Shutdown(dhBinding); // shut down the server side + Shutdown(dhBinding); // shut down the server side exit(0); -} -RPC_BINDING_HANDLE DATA_HANDLE_TYPE_bind(DATA_HANDLE_TYPE dh1) -{ -RPC_STATUS status; // returned by RPC API functions -RPC_BINDING_HANDLE hBinding; +} // end main() + +/* This _bind routine is called by the client stub immediately */ +/* before each remote procedure call. */ +RPC_BINDING_HANDLE __RPC_API DATA_HANDLE_TYPE_bind(DATA_HANDLE_TYPE dh1) +{ + RPC_STATUS status; // returned by RPC API functions + RPC_BINDING_HANDLE hBinding; + unsigned char * pszStringBinding; printf("Within DATA_HANDLE_TYPE_bind function:\n"); - status = RpcStringBindingCompose(dh1.pszUuid, - dh1.pszProtocolSequence, - dh1.pszNetworkAddress, - dh1.pszEndpoint, - dh1.pszOptions, + status = RpcStringBindingCompose(dh1->pszUuid, + dh1->pszProtocolSequence, + dh1->pszNetworkAddress, + dh1->pszEndpoint, + dh1->pszOptions, &pszStringBinding); printf("RpcStringBindingCompose returned 0x%x\n", status); printf("pszStringBinding = %s\n", pszStringBinding); - if (status) - exit(2); + if (status) { + exit(status); + } status = RpcBindingFromStringBinding(pszStringBinding, - &hBinding); + &hBinding); printf("RpcBindingFromStringBinding returned 0x%x\n", status); - if (status) - exit(2); + if (status) { + exit(status); + } + + status = RpcStringFree(&pszStringBinding); // unbind + printf("RpcStringFree returned 0x%x\n", status); + if (status) { + exit(status); + } return(hBinding); } -void DATA_HANDLE_TYPE_unbind(DATA_HANDLE_TYPE dh1, RPC_BINDING_HANDLE h1) +/* This _unbind routine is called by the client stub immediately */ +/* after each remote procedure call. */ +void __RPC_API DATA_HANDLE_TYPE_unbind(DATA_HANDLE_TYPE dh1, + RPC_BINDING_HANDLE h1) { + RPC_STATUS status; // returned by RPC API functions -RPC_STATUS status; // returned by RPC API functions + printf("Within DATA_HANDLE_TYPE_unbind function:\n"); + printf("Unbinding handle for %s\n", dh1->pszEndpoint); - printf("Within DATA_HANDLE_TYPE_unbind function:\n"); - printf("Unbinding handle for %s\n", dh1.pszEndpoint); - - status = RpcBindingFree(&h1); // unbind - printf("RpcBindingFree returned 0x%x\n", status); - status = RpcStringFree(&pszStringBinding); // remote calls done; unbind - printf("RpcStringFree returned 0x%x\n", status); + status = RpcBindingFree(&h1); // unbind + printf("RpcBindingFree returned 0x%x\n", status); } -// ==================================================================== -// 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); } -/* end usrdefc.c */ +/* end file usrdefc.c */