Annotation of mstools/ole20/samples/dispcalc/dispcalc.h, revision 1.1.1.1

1.1       root        1: /*** 
                      2: *dispcalc.h
                      3: *
                      4: *  Copyright (C) 1992, Microsoft Corporation.  All Rights Reserved.
                      5: *  Information Contained Herein Is Proprietary and Confidential.
                      6: *
                      7: *Purpose:
                      8: *  UNDONE
                      9: *
                     10: *
                     11: *Implementation Notes:
                     12: *
                     13: *****************************************************************************/
                     14: 
                     15: #include "clsid.h"
                     16: 
                     17: #ifndef CLASS
                     18: # ifdef __TURBOC__
                     19: #  define CLASS class huge
                     20: # else
                     21: #  define CLASS class FAR
                     22: # endif
                     23: #endif
                     24: 
                     25: #pragma warning(disable:4355)
                     26: 
                     27: #define DIM(X) (sizeof(X)/sizeof(X[0]))
                     28: 
                     29: 
                     30: enum operators {
                     31:     OP_NONE = 0,
                     32:     OP_PLUS,
                     33:     OP_MINUS,
                     34:     OP_MULT,
                     35:     OP_DIV
                     36: };
                     37: 
                     38: 
                     39: CLASS CCalc : public IUnknown {
                     40: public:
                     41:     static CCalc FAR* Create();
                     42: 
                     43: 
                     44:     STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppv);
                     45:     STDMETHOD_(ULONG, AddRef)(void);
                     46:     STDMETHOD_(ULONG, Release)(void);
                     47: 
                     48: 
                     49:     // Introduced "calculator" interface
                     50:     //
                     51:     // This nested class implementes core arithmetic functionality
                     52:     // (such as it is) *and* is the interface that will be exposed via
                     53:     // IDispatch for external programmability.
                     54:     //
                     55:     CLASS CArith {
                     56:     public:
                     57: 
                     58:       STDMETHOD_(void, put_Accum)(long l);
                     59:       STDMETHOD_(long, get_Accum)(void);
                     60:       STDMETHOD_(void, put_Opnd)(long l);
                     61:       STDMETHOD_(long, get_Opnd)(void);
                     62:       STDMETHOD_(void, put_Op)(short op);
                     63:       STDMETHOD_(short, get_Op)(void);
                     64:       STDMETHOD_(BOOL, Eval)(void);
                     65:       STDMETHOD_(void, Clear)(void);
                     66:       STDMETHOD_(void, Display)(void);
                     67:       STDMETHOD_(void, Quit)(void);
                     68:       STDMETHOD_(BOOL, Button)(BSTR button);
                     69: 
                     70:       // the following method is internal, and not exposed for programmability
                     71:       BOOL ButtonPush(int button);
                     72: 
                     73:       CArith(CCalc FAR* pcalc){
                     74:        m_pcalc = pcalc;
                     75:        Clear();
                     76:       }
                     77: 
                     78:       enum states { STATE_LOPND, STATE_OP, STATE_ROPND, STATE_EVAL };
                     79: 
                     80:     private:
                     81:       CCalc FAR* m_pcalc;
                     82: 
                     83:       short    m_op;
                     84:       long     m_opnd;
                     85:       long     m_accum;
                     86:       enum states m_state;
                     87:     };
                     88:     friend CArith;
                     89:     CArith m_arith;
                     90: 
                     91: 
                     92:     HWND m_hwnd;
                     93: 
                     94:     CCalc() : m_arith(this)
                     95:     {
                     96:       m_refs = 1;
                     97:       m_hwnd = 0;
                     98:       m_punkStdDisp = NULL;
                     99:     }
                    100: 
                    101: private:
                    102:     ULONG m_refs;
                    103:     IUnknown FAR* m_punkStdDisp;
                    104: };
                    105: 
                    106: 
                    107: // the following enum defines method indices used by the
                    108: // default IDispatch implementation - DispInvoke().
                    109: //
                    110: // Note: these must match the order of the preceeding declarations
                    111: //
                    112: enum IMETH_CARITH {
                    113:     IMETH_PUTACCUM = 0,
                    114:     IMETH_GETACCUM,
                    115:     IMETH_PUTOPERAND,
                    116:     IMETH_GETOPERAND,
                    117:     IMETH_PUTOPERATOR,
                    118:     IMETH_GETOPERATOR,
                    119:     IMETH_EVAL,
                    120:     IMETH_CLEAR,
                    121:     IMETH_DISPLAY,
                    122:     IMETH_QUIT,
                    123:     IMETH_BUTTON,
                    124: 
                    125:     // Define the "property" indices. these are defined to be
                    126:     // the first index in a set/get property method pair. These
                    127:     // definitions are used to build the METHODDATA that drives
                    128:     // our implementation of IDispatch. see cdisp.cpp.
                    129:     //
                    130:     IMETH_ACCUM    = IMETH_PUTACCUM,
                    131:     IMETH_OPERAND  = IMETH_PUTOPERAND,
                    132:     IMETH_OPERATOR = IMETH_PUTOPERATOR
                    133: };
                    134: 
                    135: // the following enum defines the IDs used by IDispatch
                    136: //
                    137: // Note: these values do *not* depend on order of declaration,
                    138: // but are sensitive to the kind of the method - ie, if a get/set
                    139: // method pair implements a property, then they need to share
                    140: // an ID.
                    141: //
                    142: // Note: by assigning "accum" the ID 'DISPID_VALUE', we are
                    143: // choosing to expose it as the default "value" property.
                    144: //
                    145: enum IDMEMBER_CARITH {
                    146:     IDMEMBER_ACCUM = DISPID_VALUE,     // the default property
                    147:     IDMEMBER_OPERAND,
                    148:     IDMEMBER_OPERATOR,
                    149:     IDMEMBER_EVAL,
                    150:     IDMEMBER_CLEAR,
                    151:     IDMEMBER_DISPLAY,
                    152:     IDMEMBER_QUIT,
                    153:     IDMEMBER_BUTTON
                    154: };
                    155: 
                    156: 
                    157: // the CCalc Class Factory
                    158: //
                    159: CLASS CCalcCF : public IClassFactory {
                    160: public:
                    161:     static IClassFactory FAR* Create();
                    162: 
                    163:     STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppv);
                    164:     STDMETHOD_(ULONG, AddRef)(void);
                    165:     STDMETHOD_(ULONG, Release)(void);
                    166: 
                    167:     STDMETHOD(CreateInstance)(
                    168:       IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
                    169:     STDMETHOD(LockServer)(BOOL fLock);
                    170: 
                    171:     CCalcCF() { m_refs = 1; }
                    172: 
                    173: private:
                    174:     ULONG m_refs;
                    175: };

unix.superglobalmegacorp.com

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