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

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