Annotation of mstools/samples/rpc/data/dunion/dunionc.c, revision 1.1

1.1     ! root        1: /****************************************************************************
        !             2:                          Microsoft RPC Version 1.0
        !             3:                       Copyright Microsoft Corp. 1992
        !             4:                         Discrimination Union Example
        !             5: 
        !             6:     FILE:      dunionc.c
        !             7:     USAGE:     dunionc  -n network_address
        !             8:                         -p protocol_sequence
        !             9:                         -e endpoint
        !            10:                         -o options
        !            11:                         -u uuid
        !            12:                         -s string
        !            13:                         -d discriminant
        !            14:                         -v union_value
        !            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 "dunion.h"    // header file generated by MIDL compiler
        !            26: 
        !            27: short sDiscrim = 0;
        !            28: DISCRIM_UNION_PARAM_TYPE  up = {1};
        !            29: DISCRIM_UNION_STRUCT_TYPE us = {0, 1};
        !            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, " -u uuid\n");
        !            39:     fprintf(stderr, " -s string\n");
        !            40:     fprintf(stderr, " -d discriminant\n");
        !            41:     fprintf(stderr, " -v union_value\n");
        !            42:     exit(1);
        !            43: }
        !            44: 
        !            45: void DisplayUnionValue(void)
        !            46: {
        !            47:     printf("sDiscrim = %d, data = ", sDiscrim);
        !            48:     switch(sDiscrim) {
        !            49:        case 0:
        !            50:            printf("short: %d\n", up.sVal);
        !            51:            break;
        !            52:        case 1:
        !            53:            printf("float: %f\n", up.fVal);
        !            54:            break;
        !            55:        case 2:
        !            56:            printf("char: %c\n", up.chVal);
        !            57:            break;
        !            58:        default:
        !            59:            sDiscrim = 0;
        !            60:            break;
        !            61:      }
        !            62: }
        !            63: 
        !            64: void * MIDL_user_allocate(size_t len)
        !            65: {
        !            66:     return(malloc(len));
        !            67: }
        !            68: 
        !            69: void MIDL_user_free(void * ptr)
        !            70: {
        !            71:     free(ptr);
        !            72: }
        !            73: 
        !            74: 
        !            75: void main(int argc, char **argv)
        !            76: {
        !            77:     RPC_STATUS status;             // returned by RPC API function
        !            78:     unsigned char * pszUuid = "12345678-1234-1234-1234-123456789ABC";
        !            79:     unsigned char * pszProtocolSequence = "ncacn_np";
        !            80:     unsigned char * pszNetworkAddress   = NULL;
        !            81:     unsigned char * pszEndpoint        = "\\pipe\\dunion";
        !            82:     unsigned char * pszOptions          = NULL;
        !            83:     unsigned char * pszStringBinding   = NULL;
        !            84:     int i;
        !            85: 
        !            86:     up.sVal = 1;
        !            87:     // allow the user to override settings with command line switches
        !            88:     for (i = 1; i < argc; i++) {
        !            89:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
        !            90:            switch (tolower(*(argv[i]+1))) {
        !            91:                case 'p':  // protocol sequence
        !            92:                    pszProtocolSequence = argv[++i];
        !            93:                    break;
        !            94:                case 'n':  // network address
        !            95:                    pszNetworkAddress = argv[++i];
        !            96:                    break;
        !            97:                case 'e':
        !            98:                    pszEndpoint = argv[++i];
        !            99:                    break;
        !           100:                case 'o':
        !           101:                    pszOptions = argv[++i];
        !           102:                    break;
        !           103:                case 'u':
        !           104:                    pszUuid = argv[++i];
        !           105:                    break;
        !           106:                case 'd':
        !           107:                    sDiscrim = (short) atoi(argv[++i]);
        !           108:                    if ((sDiscrim > 3) || (sDiscrim < 0))
        !           109:                        sDiscrim = 0;
        !           110:                    us.sDiscrim = sDiscrim;
        !           111:                    break;
        !           112:                case 'v':
        !           113:                    switch(sDiscrim) {
        !           114:                        case 0:
        !           115:                            up.sVal =  (short) atoi(argv[++i]);
        !           116:                            us.u.sVal = up.sVal;
        !           117:                            break;
        !           118:                        case 1:
        !           119:                            up.fVal =  (float) atof(argv[++i]);
        !           120:                            us.u.fVal = up.fVal;
        !           121:                            break;
        !           122:                        case 2:
        !           123:                            up.chVal = *(argv[++i]);
        !           124:                            us.u.chVal = up.chVal;
        !           125:                            break;
        !           126:                        default:
        !           127:                            break;
        !           128:                    }
        !           129:                case 'h':
        !           130:                case '?':
        !           131:                default:
        !           132:                    Usage(argv[0]);
        !           133:            }
        !           134:        }
        !           135:        else
        !           136:            Usage(argv[0]);
        !           137:     }
        !           138: /* Use a convenience function to concatenate the elements of  */
        !           139: /* the string binding into the proper sequence.              */
        !           140: 
        !           141:     status = RpcStringBindingCompose(pszUuid,
        !           142:                                      pszProtocolSequence,
        !           143:                                      pszNetworkAddress,
        !           144:                                      pszEndpoint,
        !           145:                                      pszOptions,
        !           146:                                      &pszStringBinding);
        !           147:     printf("RpcStringBindingCompose returned 0x%x\n", status);
        !           148:     printf("pszStringBinding = %s\n", pszStringBinding);
        !           149:     if (status)
        !           150:        exit(2);
        !           151: 
        !           152: /* Set the binding handle that will be used to bind to the server. */
        !           153: 
        !           154:     status = RpcBindingFromStringBinding(pszStringBinding,
        !           155:                                         &hDiscrim);
        !           156:     printf("RpcBindingFromStringBinding returned 0x%x\n", status);
        !           157:     if (status)
        !           158:         exit(2);
        !           159: 
        !           160:     printf("Calling the remote procedure 'UnionParamProc'\n");
        !           161: 
        !           162:     DisplayUnionValue(); // display value before call
        !           163:     UnionParamProc(up, sDiscrim);  // call the remote procedure
        !           164: 
        !           165:     UnionStructProc(us);
        !           166:     DisplayUnionValue(); // display value after call
        !           167: 
        !           168:     Shutdown();         // Shut down the server
        !           169: 
        !           170:     /* The remote procedure call is complete.  Free the binding handle */
        !           171:     status = RpcBindingFree(&hDiscrim);        // remote calls done; unbind
        !           172:     printf("RpcBindingFree returned 0x%x\n", status);
        !           173:     if (status)
        !           174:        exit(2);
        !           175: 
        !           176:     exit(0);
        !           177: }
        !           178: 
        !           179: /* end dunionc.c */

unix.superglobalmegacorp.com

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