Annotation of mstools/samples/rpc/data/inout/inoutc.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
                      2:                          Microsoft RPC Version 1.0
                      3:                        Copyright Microsoft Corp. 1992
                      4:                               InOut Example
                      5: 
                      6:     FILE:      inoutc.c
                      7:     USAGE:     inoutc   -n network_address
                      8:                         -p protocol_sequence
                      9:                         -e endpoint
                     10:                         -o options
                     11:                         -1 short_value_1
                     12:                         -2 short_value_2
                     13:                         -3 float_value_3
                     14: 
                     15:     PURPOSE:   Client side of RPC distributed application
                     16:     FUNCTIONS: main() - binds to server and calls remote procedure
                     17:     COMMENTS:
                     18: 
                     19: ****************************************************************************/
                     20: #include <stdio.h>
                     21: #include <string.h>
                     22: #include <stdlib.h>
                     23: #include <rpc.h>       // RPC API functions, types
                     24: #include "inout.h"     // header file generated by MIDL compiler
                     25: 
                     26: #define PURPOSE \
                     27: "This Microsoft RPC Version 1.0 sample program demonstrates\n\
                     28: use of the [in], [out], and [in, out] attributes. For more\n\
                     29: information about attributes and RPC API functions, see the\n\
                     30: Microsoft RPC programming guide and reference.\n\n"
                     31: 
                     32: #define DESCRIPTION \
                     33: "One [in], one [out], and one [in,out] parameter are defined\n\
                     34: for the function InOutProc(). This program displays the values\n\
                     35: of these parameters before and after the remote procedure call.\n\n"
                     36: 
                     37: void Usage(char * pszProgramName)
                     38: {
                     39:     fprintf(stderr, "%s", PURPOSE);
                     40:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     41:     fprintf(stderr, " -p protocol_sequence\n");
                     42:     fprintf(stderr, " -n network_address\n");
                     43:     fprintf(stderr, " -e endpoint\n");
                     44:     fprintf(stderr, " -o options\n");
                     45:     fprintf(stderr, " -1 parameter_1\n");
                     46:     fprintf(stderr, " -2 parameter_2\n");
                     47:     fprintf(stderr, " -3 parameter_3\n");
                     48:     exit(1);
                     49: }
                     50: 
                     51: void * MIDL_user_allocate(size_t len)
                     52: {
                     53:     return(malloc(len));
                     54: }
                     55: 
                     56: void MIDL_user_free(void * ptr)
                     57: {
                     58:     free(ptr);
                     59: }
                     60: 
1.1.1.2 ! root       61: void _CRTAPI1 main(int argc, char **argv)
1.1       root       62: {
                     63:     RPC_STATUS status;             // returned by RPC API function
1.1.1.2 ! root       64:     unsigned char * pszUuid            = NULL;
1.1       root       65:     unsigned char * pszProtocolSequence = "ncacn_np";
                     66:     unsigned char * pszNetworkAddress   = NULL;
                     67:     unsigned char * pszEndpoint        = "\\pipe\\inout";
                     68:     unsigned char * pszOptions          = NULL;
                     69:     unsigned char * pszStringBinding   = NULL;
                     70:     short   s1 = 257;
                     71:     short   s2 = 631;
                     72:     float   f3 = (float) 0.406;
                     73: 
                     74:     int i;
                     75: 
                     76:     // allow the user to override settings with command line switches
                     77:     for (i = 1; i < argc; i++) {
                     78:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
                     79:            switch (tolower(*(argv[i]+1))) {
                     80:                case 'p':  // protocol sequence
                     81:                    pszProtocolSequence = argv[++i];
                     82:                    break;
                     83:                case 'n':  // network address
                     84:                    pszNetworkAddress = argv[++i];
                     85:                    break;
                     86:                case 'e':
                     87:                    pszEndpoint = argv[++i];
                     88:                    break;
                     89:                case 'o':
                     90:                    pszOptions = argv[++i];
                     91:                    break;
                     92:                case '1':
                     93:                    s1 = (short) atoi(argv[++i]);
                     94:                    break;
                     95:                case '2':
                     96:                    s2 = (short) atoi(argv[++i]);
                     97:                    break;
                     98:                case '3':
                     99:                    f3 = (float) atof(argv[++i]);
                    100:                    break;
                    101:                case 'h':
                    102:                case '?':
                    103:                default:
                    104:                    Usage(argv[0]);
                    105:            }
                    106:        }
                    107:        else
                    108:            Usage(argv[0]);
                    109:     }
                    110:     printf("%s", DESCRIPTION);
                    111: 
                    112: /* Use a convenience function to concatenate the elements of  */
                    113: /* the string binding into the proper sequence.              */
                    114: 
                    115:     status = RpcStringBindingCompose(pszUuid,
                    116:                                      pszProtocolSequence,
                    117:                                      pszNetworkAddress,
                    118:                                      pszEndpoint,
                    119:                                      pszOptions,
                    120:                                      &pszStringBinding);
                    121:     printf("RpcStringBindingCompose returned 0x%x\n", status);
                    122:     printf("pszStringBinding = %s\n", pszStringBinding);
                    123:     if (status)
                    124:        exit(2);
                    125: 
                    126: /* Set the binding handle that will be used to bind to the server. */
                    127: 
                    128:     status = RpcBindingFromStringBinding(pszStringBinding,
                    129:                                         &inout_IfHandle);
                    130:     printf("RpcBindingFromStringBinding returned 0x%x\n", status);
                    131:     if (status)
                    132:         exit(2);
                    133: 
                    134:     printf("Calling the remote procedure 'InOutProc'\n");
                    135:     printf(" parameters = %d %d %0.3f\n", s1, s2, f3);
                    136: 
                    137:     InOutProc(s1, &s2, &f3);    // call the remote procedure
                    138: 
                    139:     printf("Returning from the remote procedure 'InOutProc'\n");
                    140:     printf(" parameters = %d %d %0.3f\n", s1, s2, f3);
                    141: 
                    142:     Shutdown();
                    143: 
                    144: /*  The call to the remote procedure is complete.  Free the binding handle */
                    145: 
                    146:     status = RpcBindingFree(&inout_IfHandle);  // remote calls done; unbind
                    147:     printf("RpcBindingFree returned 0x%x\n", status);
                    148:     if (status)
                    149:        exit(2);
                    150: 
                    151:     status = RpcStringFree(&pszStringBinding); // free memory for string
                    152:     printf("RpcStringFree returned 0x%x\n", status);
                    153:     if (status)
                    154:        exit(2);
                    155: 
                    156:     exit(0);
                    157: 
                    158: } /* end inoutc.c */

unix.superglobalmegacorp.com

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