|
|
1.1 ! root 1: /*** ! 2: *cpoint.cpp - Implementation of the CPoint object. ! 3: * ! 4: * Copyright (C) 1992, Microsoft Corporation. All Rights Reserved. ! 5: * Information Contained Herein Is Proprietary and Confidential. ! 6: * ! 7: *Purpose: ! 8: * This module implements the CPoint class. The class implements two ! 9: * properties, and exposes them via IDispatch. ! 10: * ! 11: * This module is intended as a sample implementation of the IDispatch ! 12: * interface, and its purpose is to demonstrate how an object can ! 13: * expose methods and properties for programatic and cross-process ! 14: * access via the IDispatch interface. ! 15: * ! 16: *Implementation Notes: ! 17: * ! 18: *****************************************************************************/ ! 19: ! 20: #include <windows.h> ! 21: #include <ole2.h> ! 22: #if !defined(WIN32) ! 23: #include <olenls.h> ! 24: #endif ! 25: #include <dispatch.h> ! 26: ! 27: #include "spoly.h" ! 28: #include "cpoint.h" ! 29: ! 30: ! 31: CPoint::CPoint() ! 32: { ! 33: m_x = 0; ! 34: m_y = 0; ! 35: m_refs = 0; ! 36: m_ptinfo = NULL; ! 37: } ! 38: ! 39: ! 40: CPoint::~CPoint() ! 41: { ! 42: } ! 43: ! 44: ! 45: /*** ! 46: *CPoint::Create(void) ! 47: *Purpose: ! 48: * Create an instance of a CPoint object. ! 49: * ! 50: *Entry: ! 51: * None ! 52: * ! 53: *Exit: ! 54: * returns a CPoint*, NULL if creation failed. ! 55: * ! 56: ***********************************************************************/ ! 57: CPoint FAR* ! 58: CPoint::Create() ! 59: { ! 60: HRESULT hresult; ! 61: CPoint FAR* ppoint; ! 62: ITypeInfo FAR* ptinfo; ! 63: extern INTERFACEDATA NEAR g_idataCPoint; ! 64: ! 65: ! 66: if((ppoint = new FAR CPoint()) == NULL) ! 67: return NULL; ! 68: ppoint->AddRef(); ! 69: ! 70: hresult = ! 71: CreateDispTypeInfo(&g_idataCPoint, LOCALE_SYSTEM_DEFAULT, &ptinfo); ! 72: if(hresult != NOERROR) ! 73: goto LError0; ! 74: ! 75: ppoint->m_ptinfo = ptinfo; ! 76: ! 77: return ppoint; ! 78: ! 79: LError0:; ! 80: ppoint->Release(); ! 81: ! 82: return NULL; ! 83: } ! 84: ! 85: ! 86: //--------------------------------------------------------------------- ! 87: // IUnknown Methods ! 88: //--------------------------------------------------------------------- ! 89: ! 90: ! 91: STDMETHODIMP ! 92: CPoint::QueryInterface(REFIID iid, void FAR* FAR* ppv) ! 93: { ! 94: if(iid == IID_IUnknown || iid == IID_IDispatch){ ! 95: *ppv = this; ! 96: AddRef(); ! 97: return NOERROR; ! 98: } ! 99: *ppv = NULL; ! 100: return ResultFromScode(E_NOINTERFACE); ! 101: } ! 102: ! 103: ! 104: STDMETHODIMP_(ULONG) ! 105: CPoint::AddRef(void) ! 106: { ! 107: return ++m_refs; ! 108: } ! 109: ! 110: ! 111: STDMETHODIMP_(ULONG) ! 112: CPoint::Release(void) ! 113: { ! 114: if(--m_refs == 0){ ! 115: if(m_ptinfo != NULL){ ! 116: m_ptinfo->Release(); ! 117: } ! 118: delete this; ! 119: return 0; ! 120: } ! 121: return m_refs; ! 122: } ! 123: ! 124: ! 125: //--------------------------------------------------------------------- ! 126: // IDispatch methods ! 127: //--------------------------------------------------------------------- ! 128: ! 129: ! 130: STDMETHODIMP ! 131: CPoint::GetTypeInfoCount(UINT FAR* pctinfo) ! 132: { ! 133: // this object has a single *introduced* interface ! 134: // ! 135: *pctinfo = 1; ! 136: ! 137: return NOERROR; ! 138: } ! 139: ! 140: ! 141: STDMETHODIMP ! 142: CPoint::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo) ! 143: { ! 144: if(itinfo != 0) ! 145: return ResultFromScode(DISP_E_BADINDEX); ! 146: ! 147: m_ptinfo->AddRef(); ! 148: *pptinfo = m_ptinfo; ! 149: ! 150: return NOERROR; ! 151: } ! 152: ! 153: ! 154: /*** ! 155: *HRESULT CPoint::GetIDsOfNames(REFIID, char**, UINT, LCID, LONG*) ! 156: *Purpose: ! 157: * This method translates the given array of names to a corresponding ! 158: * array of DISPIDs. ! 159: * ! 160: * Index 0 of the name array is the member name, and indices 1-N if ! 161: * present represent named parameters on that member. ! 162: * ! 163: * The local ID ('lcid') is unused by this naive implementation. A more ! 164: * sophisticated implementation, sensitive to localization and natural ! 165: * language support would use the locale ID to interpret the given names ! 166: * in a correct locale specific context. ! 167: * ! 168: *Entry: ! 169: * rgszNames = pointer to an array of names ! 170: * cNames = the number of names in the rgszNames array ! 171: * lcid = the callers locale ID ! 172: * ! 173: *Exit: ! 174: * return value = HRESULT ! 175: * rgid = array of name IDs corresponding to the rgszNames array ! 176: * this array will contain -1 for each entry that is not known. ! 177: * ! 178: ***********************************************************************/ ! 179: STDMETHODIMP ! 180: CPoint::GetIDsOfNames( ! 181: REFIID riid, ! 182: char FAR* FAR* rgszNames, ! 183: UINT cNames, ! 184: LCID lcid, ! 185: DISPID FAR* rgdispid) ! 186: { ! 187: return DispGetIDsOfNames(m_ptinfo, rgszNames, cNames, rgdispid); ! 188: } ! 189: ! 190: ! 191: /*** ! 192: *HRESULT CPoint::Invoke(...) ! 193: *Purpose: ! 194: * Dispatch a method or property request for objects of type CPoint. ! 195: * ! 196: * see the IDispatch document for more information, and a general ! 197: * description of this method. ! 198: * ! 199: *Entry: ! 200: * dispidMember = the DISPID of the member being requested ! 201: * ! 202: * riid = reference to the interface ID of the interface on this object ! 203: * that the requested member belongs to. IID_NULL means to interpret ! 204: * the member as belonging to the implementation defined "default" ! 205: * or "primary" interface. ! 206: * ! 207: * lcid = the caller's locale ID ! 208: * ! 209: * wFlags = flags indicating the type of access being requested ! 210: * ! 211: * pdispparams = pointer to the DISPPARAMS struct containing the ! 212: * requested members arguments (if any) and its named parameter ! 213: * DISPIDs (if any). ! 214: * ! 215: *Exit: ! 216: * return value = HRESULT ! 217: * see the IDispatch spec for a description of possible success codes. ! 218: * ! 219: * pvarResult = pointer to a caller allocated VARIANT containing ! 220: * the members return value (if any). ! 221: * ! 222: * pexcepinfo = caller allocated exception info structure, this will ! 223: * be filled in only if an exception was raised that must be passed ! 224: * up through Invoke to an enclosing handler. ! 225: * ! 226: * puArgErr = pointer to a caller allocated UINT, that will contain the ! 227: * index of the offending argument if a DISP_E_TYPEMISMATCH error ! 228: * was returned indicating that one of the arguments was of an ! 229: * incorrect type and/or could not be reasonably coerced to a proper ! 230: * type. ! 231: * ! 232: ***********************************************************************/ ! 233: STDMETHODIMP ! 234: CPoint::Invoke( ! 235: DISPID dispidMember, ! 236: REFIID riid, ! 237: LCID lcid, ! 238: WORD wFlags, ! 239: DISPPARAMS FAR* pdispparams, ! 240: VARIANT FAR* pvarResult, ! 241: EXCEPINFO FAR* pexcepinfo, ! 242: UINT FAR* puArgErr) ! 243: { ! 244: return DispInvoke( ! 245: this, m_ptinfo, ! 246: dispidMember, wFlags, pdispparams, ! 247: pvarResult, pexcepinfo, puArgErr); ! 248: } ! 249: ! 250: ! 251: //--------------------------------------------------------------------- ! 252: // Introduced methods ! 253: //--------------------------------------------------------------------- ! 254: ! 255: short METHODCALLTYPE EXPORT ! 256: CPoint::GetX() ! 257: { ! 258: return m_x; ! 259: } ! 260: ! 261: void METHODCALLTYPE EXPORT ! 262: CPoint::SetX(short x) ! 263: { ! 264: m_x = x; ! 265: } ! 266: ! 267: short METHODCALLTYPE EXPORT ! 268: CPoint::GetY() ! 269: { ! 270: return m_y; ! 271: } ! 272: ! 273: void METHODCALLTYPE EXPORT ! 274: CPoint::SetY(short y) ! 275: { ! 276: m_y = y; ! 277: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.