|
|
1.1 root 1: /**************************************************************************** 1.1.1.3 ! root 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: usrdef Example ! 5: ! 6: FILE: usrdefc.c ! 7: ! 8: USAGE: usrdefc -n network_address ! 9: -p protocol_sequence ! 10: -e endpoint ! 11: -o options ! 12: ! 13: PURPOSE: Client side of RPC distributed application ! 14: ! 15: FUNCTIONS: main() - binds to server and calls remote procedure ! 16: ! 17: COMMENTS: This distributed application uses a user-defined handle. ! 18: 1.1 root 19: ****************************************************************************/ 20: 1.1.1.3 ! root 21: #include <stdlib.h> ! 22: #include <stdio.h> ! 23: #include <ctype.h> ! 24: #include "usrdef.h" // header file generated by MIDL compiler 1.1 root 25: 26: void Usage(char * pszProgramName) 27: { 28: fprintf(stderr, "Usage: %s\n", pszProgramName); 29: fprintf(stderr, " -p protocol_sequence\n"); 30: fprintf(stderr, " -n network_address\n"); 31: fprintf(stderr, " -e endpoint\n"); 32: fprintf(stderr, " -o options\n"); 33: fprintf(stderr, " -s string\n"); 34: exit(1); 35: } 36: 1.1.1.2 root 37: void _CRTAPI1 main(int argc, char **argv) 1.1 root 38: { 1.1.1.3 ! root 39: int i; ! 40: DATA_HANDLE_TYPE dhBinding; ! 41: unsigned char * pszString = "hello, world"; ! 42: ! 43: dhBinding = (DATA_HANDLE_TYPE) midl_user_allocate(sizeof(DATA_TYPE)); ! 44: dhBinding->pszProtocolSequence = "ncacn_np"; ! 45: dhBinding->pszUuid = NULL; ! 46: dhBinding->pszEndpoint = "\\pipe\\usrdef"; ! 47: dhBinding->pszNetworkAddress = NULL; ! 48: dhBinding->pszOptions = NULL; 1.1 root 49: 1.1.1.3 ! root 50: /* allow the user to override settings with command line switches */ 1.1 root 51: for (i = 1; i < argc; i++) { 1.1.1.3 ! root 52: if ((*argv[i] == '-') || (*argv[i] == '/')) { ! 53: switch (tolower(*(argv[i]+1))) { ! 54: case 'p': // protocol sequence ! 55: dhBinding->pszProtocolSequence = argv[++i]; ! 56: break; ! 57: case 'n': // network address ! 58: dhBinding->pszNetworkAddress = argv[++i]; ! 59: break; ! 60: case 'e': ! 61: dhBinding->pszEndpoint = argv[++i]; ! 62: break; ! 63: case 'o': ! 64: dhBinding->pszOptions = argv[++i]; ! 65: break; ! 66: case 's': ! 67: pszString = argv[++i]; ! 68: break; ! 69: case 'h': ! 70: case '?': ! 71: default: ! 72: Usage(argv[0]); ! 73: } ! 74: } ! 75: else ! 76: Usage(argv[0]); 1.1 root 77: } 78: 79: printf("Calling the remote procedure 'UsrdefProc'\n"); 1.1.1.3 ! root 80: UsrdefProc(dhBinding, pszString); // call the remote procedure 1.1 root 81: 82: printf("Calling the remote procedure 'Shutdown'\n"); 1.1.1.3 ! root 83: Shutdown(dhBinding); // shut down the server side 1.1 root 84: 85: exit(0); 86: 1.1.1.3 ! root 87: } // end main() ! 88: ! 89: /* This _bind routine is called by the client stub immediately */ ! 90: /* before each remote procedure call. */ ! 91: RPC_BINDING_HANDLE __RPC_API DATA_HANDLE_TYPE_bind(DATA_HANDLE_TYPE dh1) ! 92: { ! 93: RPC_STATUS status; // returned by RPC API functions ! 94: RPC_BINDING_HANDLE hBinding; ! 95: unsigned char * pszStringBinding; 1.1 root 96: 97: printf("Within DATA_HANDLE_TYPE_bind function:\n"); 1.1.1.3 ! root 98: status = RpcStringBindingCompose(dh1->pszUuid, ! 99: dh1->pszProtocolSequence, ! 100: dh1->pszNetworkAddress, ! 101: dh1->pszEndpoint, ! 102: dh1->pszOptions, 1.1 root 103: &pszStringBinding); 104: printf("RpcStringBindingCompose returned 0x%x\n", status); 105: printf("pszStringBinding = %s\n", pszStringBinding); 1.1.1.3 ! root 106: if (status) { ! 107: exit(status); ! 108: } 1.1 root 109: 110: status = RpcBindingFromStringBinding(pszStringBinding, 1.1.1.3 ! root 111: &hBinding); 1.1 root 112: printf("RpcBindingFromStringBinding returned 0x%x\n", status); 1.1.1.3 ! root 113: if (status) { ! 114: exit(status); ! 115: } ! 116: ! 117: status = RpcStringFree(&pszStringBinding); // unbind ! 118: printf("RpcStringFree returned 0x%x\n", status); ! 119: if (status) { ! 120: exit(status); ! 121: } 1.1 root 122: 123: return(hBinding); 124: } 125: 1.1.1.3 ! root 126: /* This _unbind routine is called by the client stub immediately */ ! 127: /* after each remote procedure call. */ ! 128: void __RPC_API DATA_HANDLE_TYPE_unbind(DATA_HANDLE_TYPE dh1, ! 129: RPC_BINDING_HANDLE h1) 1.1 root 130: { 1.1.1.3 ! root 131: RPC_STATUS status; // returned by RPC API functions 1.1 root 132: 1.1.1.3 ! root 133: printf("Within DATA_HANDLE_TYPE_unbind function:\n"); ! 134: printf("Unbinding handle for %s\n", dh1->pszEndpoint); 1.1 root 135: 1.1.1.3 ! root 136: status = RpcBindingFree(&h1); // unbind ! 137: printf("RpcBindingFree returned 0x%x\n", status); 1.1 root 138: } 139: 1.1.1.3 ! root 140: /*********************************************************************/ ! 141: /* MIDL allocate and free */ ! 142: /*********************************************************************/ 1.1 root 143: 1.1.1.3 ! root 144: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) 1.1 root 145: { 146: return(malloc(len)); 147: } 148: 1.1.1.3 ! root 149: void __RPC_API midl_user_free(void __RPC_FAR * ptr) 1.1 root 150: { 151: free(ptr); 152: } 153: 1.1.1.3 ! root 154: /* end file usrdefc.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.