Annotation of mstools/samples/rpc/handles/usrdef/usrdefc.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
                      2:                          Microsoft RPC Version 1.0
                      3:                        Copyright Microsoft Corp. 1992
                      4:                               usrdef Example
                      5: 
                      6:     FILE:      usrdefc.c
                      7:     USAGE:     client   -n network_address
                      8:                         -p protocol_sequence
                      9:                         -e endpoint
                     10:                         -o options
                     11: 
                     12:     PURPOSE:   Client side of RPC distributed application
                     13:     FUNCTIONS: main() - binds to server and calls remote procedure
                     14:     COMMENTS:
                     15: ****************************************************************************/
                     16: #include <stdio.h>
                     17: #include <string.h>
                     18: #include <stdlib.h>
                     19: #include <rpc.h>       // RPC API functions, types
                     20: #include "usrdef.h"     // header file generated by MIDL compiler
                     21: 
                     22: unsigned char * pszStringBinding;
                     23: 
                     24: void Usage(char * pszProgramName)
                     25: {
                     26:     fprintf(stderr, "Usage:  %s\n", pszProgramName);
                     27:     fprintf(stderr, " -p protocol_sequence\n");
                     28:     fprintf(stderr, " -n network_address\n");
                     29:     fprintf(stderr, " -e endpoint\n");
                     30:     fprintf(stderr, " -o options\n");
                     31:     fprintf(stderr, " -s string\n");
                     32:     exit(1);
                     33: }
                     34: 
1.1.1.2 ! root       35: void _CRTAPI1 main(int argc, char **argv)
1.1       root       36: {
                     37: int i;
                     38: DATA_HANDLE_TYPE dhBinding;
                     39: unsigned char * pszString = "hello, world";
                     40: 
                     41:     dhBinding.pszProtocolSequence = "ncacn_np";
1.1.1.2 ! root       42:     dhBinding.pszUuid            = NULL;
        !            43:     dhBinding.pszEndpoint        =  "\\pipe\\usrdef";
        !            44:     dhBinding.pszNetworkAddress   = NULL;
        !            45:     dhBinding.pszOptions         = NULL;
1.1       root       46: 
                     47:     // allow the user to override settings with command line switches
                     48:     for (i = 1; i < argc; i++) {
                     49:        if ((*argv[i] == '-') || (*argv[i] == '/')) {
                     50:            switch (tolower(*(argv[i]+1))) {
                     51:                case 'p':  // protocol sequence
                     52:                    dhBinding.pszProtocolSequence = argv[++i];
                     53:                    break;
                     54:                case 'n':  // network address
                     55:                    dhBinding.pszNetworkAddress = argv[++i];
                     56:                    break;
                     57:                case 'e':
                     58:                    dhBinding.pszEndpoint = argv[++i];
                     59:                    break;
                     60:                case 'o':
                     61:                    dhBinding.pszOptions = argv[++i];
                     62:                    break;
                     63:                case 's':
                     64:                    pszString = argv[++i];
                     65:                    break;
                     66:                case 'h':
                     67:                case '?':
                     68:                default:
                     69:                    Usage(argv[0]);
                     70:            }
                     71:        }
                     72:        else
                     73:            Usage(argv[0]);
                     74:     }
                     75: 
                     76:     printf("Calling the remote procedure 'UsrdefProc'\n");
                     77: 
                     78:     UsrdefProc(dhBinding, pszString);   // call the remote procedure
                     79: 
                     80:     printf("Calling the remote procedure 'Shutdown'\n");
                     81:     Shutdown(dhBinding);                // shut down the server side
                     82: 
                     83:     exit(0);
                     84: }
                     85: 
                     86: RPC_BINDING_HANDLE DATA_HANDLE_TYPE_bind(DATA_HANDLE_TYPE dh1)
                     87: {
                     88: RPC_STATUS status;                // returned by RPC API functions
                     89: RPC_BINDING_HANDLE hBinding;
                     90: 
                     91:     printf("Within DATA_HANDLE_TYPE_bind function:\n");
                     92:     status = RpcStringBindingCompose(dh1.pszUuid,
                     93:                                     dh1.pszProtocolSequence,
                     94:                                     dh1.pszNetworkAddress,
                     95:                                     dh1.pszEndpoint,
                     96:                                     dh1.pszOptions,
                     97:                                      &pszStringBinding);
                     98:     printf("RpcStringBindingCompose returned 0x%x\n", status);
                     99:     printf("pszStringBinding = %s\n", pszStringBinding);
                    100:     if (status)
                    101:        exit(2);
                    102: 
                    103:     status = RpcBindingFromStringBinding(pszStringBinding,
                    104:                                         &hBinding);
                    105:     printf("RpcBindingFromStringBinding returned 0x%x\n", status);
                    106:     if (status)
                    107:         exit(2);
                    108: 
                    109:     return(hBinding);
                    110: }
                    111: 
                    112: void DATA_HANDLE_TYPE_unbind(DATA_HANDLE_TYPE dh1, RPC_BINDING_HANDLE h1)
                    113: {
                    114: 
                    115: RPC_STATUS status;                // returned by RPC API functions
                    116: 
                    117:     printf("Within DATA_HANDLE_TYPE_unbind function:\n");
                    118:     printf("Unbinding handle for %s\n", dh1.pszEndpoint);
                    119: 
                    120:     status = RpcBindingFree(&h1);      // unbind
                    121:     printf("RpcBindingFree returned 0x%x\n", status);
                    122:     status = RpcStringFree(&pszStringBinding); // remote calls done; unbind
                    123:     printf("RpcStringFree returned 0x%x\n", status);
                    124: }
                    125: 
                    126: // ====================================================================
                    127: //                MIDL allocate and free
                    128: // ====================================================================
                    129: 
                    130: 
                    131: void * MIDL_user_allocate(size_t len)
                    132: {
                    133:     return(malloc(len));
                    134: }
                    135: 
                    136: void MIDL_user_free(void * ptr)
                    137: {
                    138:     free(ptr);
                    139: }
                    140: 
                    141: /* end usrdefc.c */

unix.superglobalmegacorp.com

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