|
|
1.1 ! root 1: /**************************************************************************** ! 2: Microsoft RPC Version 1.0 ! 3: Copyright Microsoft Corp. 1992 ! 4: Cluuid Example ! 5: ! 6: FILE: cluuidc.c ! 7: ! 8: USAGE: cluuidc -n network_address ! 9: -p protocol_sequence ! 10: -e endpoint ! 11: -o options ! 12: -s string_displayed_on_server ! 13: -u client object uuid ! 14: ! 15: PURPOSE: Client side of RPC distributed application ! 16: ! 17: FUNCTIONS: main() - binds to server and calls remote procedure ! 18: ! 19: COMMENTS: This distributed application prints a string such as ! 20: "hello, world" on the server. The client manages its ! 21: connection to the server. The client uses the implicit ! 22: binding handle ImpHandle defined in the file cluuid.h. ! 23: ! 24: ****************************************************************************/ ! 25: ! 26: #include <stdio.h> ! 27: #include <stdlib.h> ! 28: #include <ctype.h> ! 29: #include "cluuid.h" // header file generated by MIDL compiler ! 30: ! 31: void Usage(char * pszProgramName) ! 32: { ! 33: fprintf(stderr, "Usage: %s\n", pszProgramName); ! 34: fprintf(stderr, " -p protocol_sequence\n"); ! 35: fprintf(stderr, " -n network_address\n"); ! 36: fprintf(stderr, " -e endpoint\n"); ! 37: fprintf(stderr, " -o options\n"); ! 38: fprintf(stderr, " -s string\n"); ! 39: fprintf(stderr, " -u uuid\n"); ! 40: exit(1); ! 41: } ! 42: ! 43: void _CRTAPI1 main(int argc, char **argv) ! 44: { ! 45: RPC_STATUS status; ! 46: unsigned char * pszUuid = NULL; ! 47: unsigned char * pszProtocolSequence = "ncacn_np"; ! 48: unsigned char * pszNetworkAddress = NULL; ! 49: unsigned char * pszEndpoint = "\\pipe\\cluuid"; ! 50: unsigned char * pszOptions = NULL; ! 51: unsigned char * pszStringBinding = NULL; ! 52: unsigned char * pszString = "hello, world"; ! 53: unsigned long ulCode; ! 54: int i; ! 55: ! 56: /* allow the user to override settings with command line switches */ ! 57: for (i = 1; i < argc; i++) { ! 58: if ((*argv[i] == '-') || (*argv[i] == '/')) { ! 59: switch (tolower(*(argv[i]+1))) { ! 60: case 'p': // protocol sequence ! 61: pszProtocolSequence = argv[++i]; ! 62: break; ! 63: case 'n': // network address ! 64: pszNetworkAddress = argv[++i]; ! 65: break; ! 66: case 'e': ! 67: pszEndpoint = argv[++i]; ! 68: break; ! 69: case 'o': ! 70: pszOptions = argv[++i]; ! 71: break; ! 72: case 's': ! 73: pszString = argv[++i]; ! 74: break; ! 75: case 'u': ! 76: pszUuid = argv[++i]; ! 77: break; ! 78: case 'h': ! 79: case '?': ! 80: default: ! 81: Usage(argv[0]); ! 82: } ! 83: } ! 84: else ! 85: Usage(argv[0]); ! 86: } ! 87: ! 88: /* Use a convenience function to concatenate the elements of */ ! 89: /* the string binding into the proper sequence. */ ! 90: status = RpcStringBindingCompose(pszUuid, ! 91: pszProtocolSequence, ! 92: pszNetworkAddress, ! 93: pszEndpoint, ! 94: pszOptions, ! 95: &pszStringBinding); ! 96: printf("RpcStringBindingCompose returned 0x%x\n", status); ! 97: printf("pszStringBinding = %s\n", pszStringBinding); ! 98: if (status) { ! 99: exit(status); ! 100: } ! 101: ! 102: /* Set the binding handle that will be used to bind to the server. */ ! 103: status = RpcBindingFromStringBinding(pszStringBinding, ! 104: &ImpHandle); ! 105: printf("RpcBindingFromStringBinding returned 0x%x\n", status); ! 106: if (status) { ! 107: exit(status); ! 108: } ! 109: ! 110: printf("Calling the remote procedure 'HelloProc'\n"); ! 111: printf(" print the string '%s' on the server\n", pszString); ! 112: ! 113: RpcTryExcept { ! 114: HelloProc(pszString); /* make call with user message */ ! 115: printf("Calling the remote procedure 'Shutdown'\n"); ! 116: Shutdown(); // shut down the server side ! 117: } ! 118: RpcExcept(1) { ! 119: ulCode = RpcExceptionCode(); ! 120: printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode); ! 121: } ! 122: RpcEndExcept ! 123: ! 124: /* The calls to the remote procedures are complete. */ ! 125: /* Free the string and the binding handle */ ! 126: ! 127: status = RpcStringFree(&pszStringBinding); // remote calls done; unbind ! 128: printf("RpcStringFree returned 0x%x\n", status); ! 129: if (status) { ! 130: exit(status); ! 131: } ! 132: ! 133: status = RpcBindingFree(&ImpHandle); // remote calls done; unbind ! 134: printf("RpcBindingFree returned 0x%x\n", status); ! 135: if (status) { ! 136: exit(status); ! 137: } ! 138: ! 139: exit(0); ! 140: } ! 141: ! 142: ! 143: /*********************************************************************/ ! 144: /* MIDL allocate and free */ ! 145: /*********************************************************************/ ! 146: ! 147: void __RPC_FAR * __RPC_API midl_user_allocate(size_t len) ! 148: { ! 149: return(malloc(len)); ! 150: } ! 151: ! 152: void __RPC_API midl_user_free(void __RPC_FAR * ptr) ! 153: { ! 154: free(ptr); ! 155: } ! 156: ! 157: ! 158: /* end file cluuidc.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.