Annotation of mstools/samples/rpc/hello/helloc.c, revision 1.1.1.3

1.1       root        1: /****************************************************************************
1.1.1.3 ! root        2:                   Microsoft RPC Version 1.0
        !             3:                 Copyright Microsoft Corp. 1992
        !             4:                        Hello Example
        !             5: 
        !             6:     FILE:       helloc.c
        !             7: 
        !             8:     USAGE:      helloc  -n network_address
        !             9:                         -p protocol_sequence
        !            10:                         -e endpoint
        !            11:                         -o options
        !            12:                         -s string_displayed_on_server
        !            13: 
        !            14:     PURPOSE:    Client side of RPC distributed application
        !            15: 
        !            16:     FUNCTIONS:  main() - binds to server and calls remote procedure
        !            17: 
        !            18:     COMMENTS:   This version of the distributed application that 
        !            19:                 prints "hello, world" (or other string) on the server 
        !            20:                 features a client that manages its connection to the 
        !            21:                 server. It uses the binding handle hello_IfHandle, 
        !            22:                 defined in the file hello.h.
1.1       root       23: 
                     24: ****************************************************************************/
1.1.1.3 ! root       25: 
1.1       root       26: #include <stdlib.h>
1.1.1.3 ! root       27: #include <stdio.h>
        !            28: #include <ctype.h>
        !            29: #include "hello.h"    // header file generated by MIDL compiler
1.1       root       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:     exit(1);
                     40: }
                     41: 
1.1.1.2   root       42: void _CRTAPI1 main(int argc, char **argv)
1.1       root       43: {
1.1.1.3 ! root       44:     RPC_STATUS status;  
        !            45:     unsigned char * pszUuid             = NULL;
1.1       root       46:     unsigned char * pszProtocolSequence = "ncacn_np";
                     47:     unsigned char * pszNetworkAddress   = NULL;
1.1.1.3 ! root       48:     unsigned char * pszEndpoint         = "\\pipe\\hello";
1.1       root       49:     unsigned char * pszOptions          = NULL;
1.1.1.3 ! root       50:     unsigned char * pszStringBinding    = NULL;
        !            51:     unsigned char * pszString           = "hello, world";
1.1.1.2   root       52:     unsigned long ulCode;
1.1       root       53:     int i;
                     54: 
1.1.1.3 ! root       55:     /* allow the user to override settings with command line switches */
1.1       root       56:     for (i = 1; i < argc; i++) {
1.1.1.3 ! root       57:         if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            58:             switch (tolower(*(argv[i]+1))) {
        !            59:             case 'p':  // protocol sequence
        !            60:                 pszProtocolSequence = argv[++i];
        !            61:                 break;
        !            62:             case 'n':  // network address
        !            63:                 pszNetworkAddress = argv[++i];
        !            64:                 break;
        !            65:             case 'e':  // endpoint
        !            66:                 pszEndpoint = argv[++i];
        !            67:                 break;
        !            68:             case 'o':
        !            69:                 pszOptions = 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]);
1.1       root       82:     }
                     83: 
1.1.1.3 ! root       84:     /* Use a convenience function to concatenate the elements of */
        !            85:     /* the string binding into the proper sequence.              */
1.1       root       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);
1.1.1.3 ! root       94:     if (status) {
        !            95:         exit(status);
        !            96:     }
1.1       root       97: 
1.1.1.3 ! root       98:     /* Set the binding handle that will be used to bind to the server. */
1.1       root       99:     status = RpcBindingFromStringBinding(pszStringBinding,
1.1.1.3 ! root      100:                                          &hello_IfHandle);
1.1       root      101:     printf("RpcBindingFromStringBinding returned 0x%x\n", status);
1.1.1.3 ! root      102:     if (status) {
        !           103:         exit(status);
        !           104:     }
1.1       root      105: 
                    106:     printf("Calling the remote procedure 'HelloProc'\n");
1.1.1.3 ! root      107:     printf("Print the string '%s' on the server\n", pszString);
1.1       root      108: 
                    109:     RpcTryExcept {
1.1.1.3 ! root      110:         HelloProc(pszString);  // make call with user message 
        !           111:         printf("Calling the remote procedure 'Shutdown'\n");
        !           112:         Shutdown();  // shut down the server side
1.1       root      113:     }
                    114:     RpcExcept(1) {
1.1.1.3 ! root      115:         ulCode = RpcExceptionCode();
        !           116:         printf("Runtime reported exception 0x%lx = %ld\n", ulCode, ulCode);
1.1       root      117:     }
                    118:     RpcEndExcept
                    119: 
1.1.1.3 ! root      120:     /*  The calls to the remote procedures are complete. */
        !           121:     /*  Free the string and the binding handle           */
        !           122:     status = RpcStringFree(&pszStringBinding);  // remote calls done; unbind
1.1       root      123:     printf("RpcStringFree returned 0x%x\n", status);
1.1.1.3 ! root      124:     if (status) {
        !           125:         exit(status);
        !           126:     }
1.1       root      127: 
                    128:     status = RpcBindingFree(&hello_IfHandle);  // remote calls done; unbind
                    129:     printf("RpcBindingFree returned 0x%x\n", status);
1.1.1.3 ! root      130:     if (status) {
        !           131:         exit(status);
        !           132:     }
1.1       root      133: 
                    134:     exit(0);
                    135: 
1.1.1.3 ! root      136: }  // end main()
1.1       root      137: 
                    138: 
1.1.1.3 ! root      139: /*********************************************************************/
        !           140: /*                 MIDL allocate and free                            */
        !           141: /*********************************************************************/
1.1       root      142: 
1.1.1.3 ! root      143: void  __RPC_FAR * __RPC_API midl_user_allocate(size_t len)
1.1       root      144: {
                    145:     return(malloc(len));
                    146: }
                    147: 
1.1.1.3 ! root      148: void __RPC_API midl_user_free(void __RPC_FAR * ptr)
1.1       root      149: {
                    150:     free(ptr);
                    151: }
                    152: 
                    153: /* end file helloc.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.