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