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

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