Annotation of mstools/ole20/samples/dispdemo/crempoly.cpp, revision 1.1

1.1     ! root        1: /*** 
        !             2: *crempoly.cpp
        !             3: *
        !             4: *  Copyright (C) 1992, Microsoft Corporation.  All Rights Reserved.
        !             5: *  Information Contained Herein Is Proprietary and Confidential.
        !             6: *
        !             7: *Purpose:
        !             8: *  This file contains the implementation of CRemPoly, the remote polygon
        !             9: *  class. This class presents a standard C++ vtable interface to the
        !            10: *  rest of the application, and hides the details of talking to the
        !            11: *  actual remote CPoly class exposed by the SPoly server. Each of
        !            12: *  the introduced methods is simply a cover for an IDispatch invocation
        !            13: *  of the actual method on the remote object.
        !            14: *
        !            15: *Implementation Notes:
        !            16: *
        !            17: *****************************************************************************/
        !            18: 
        !            19: #include "dispdemo.h"
        !            20: #include "crempoly.h"
        !            21: 
        !            22: extern int g_fTrace;
        !            23: 
        !            24: // method names on the CPoly class.
        !            25: //
        !            26: char FAR* CRemPoly::m_rgszMethods[] = {
        !            27:     "draw",
        !            28:     "dump",
        !            29:     "reset",
        !            30:     "addpoint",
        !            31:     "enumpoints",
        !            32:     "getxorigin",
        !            33:     "setxorigin",
        !            34:     "getyorigin",
        !            35:     "setyorigin",
        !            36:     "getwidth",
        !            37:     "setwidth",
        !            38:     "get_red",
        !            39:     "set_red",
        !            40:     "get_green",
        !            41:     "set_green",
        !            42:     "get_blue",
        !            43:     "set_blue"
        !            44: };
        !            45: 
        !            46: #ifdef _MAC
        !            47: # define IfMac(X) (X)
        !            48: # define IfWin(X)
        !            49: #else
        !            50: # define IfMac(X)
        !            51: # define IfWin(X) (X)
        !            52: #endif
        !            53: 
        !            54: 
        !            55: CRemPoly::CRemPoly()
        !            56: {
        !            57:     m_refs = 0;
        !            58:     m_pdisp = (IDispatch FAR*)NULL;
        !            59: }
        !            60: 
        !            61: 
        !            62: // A useful pre-initialized DISPATCHPARAMS, used on all the methods that
        !            63: // take 0 arguments.
        !            64: //
        !            65: DISPPARAMS NEAR g_dispparamsNoArgs = {NULL, NULL, 0, 0};
        !            66: 
        !            67: 
        !            68: /***
        !            69: *HRESULT CRemPoly::Create(clsid, CRemPoly**)
        !            70: *
        !            71: *Purpose:
        !            72: *  This function creates an instance of the CRemPoly class, connects
        !            73: *  it to the IDispatch interface of the remote CPoly class, and learns
        !            74: *  the DISPIDs for the members (that we know about) exposed by that
        !            75: *  class.
        !            76: *
        !            77: *Entry:
        !            78: *  clsid = The CLSID of the CPoly we are to create. (taking this as a
        !            79: *    param is a bit weird, but allows us to connect to several remote
        !            80: *    versions.
        !            81: *
        !            82: *Exit:
        !            83: *  return value = HRESULT
        !            84: *
        !            85: *  *pprempoly = pointer to the newly created CRemPoly, if successfyl.
        !            86: *
        !            87: ***********************************************************************/
        !            88: HRESULT
        !            89: CRemPoly::Create(CLSID clsid, CRemPoly FAR* FAR* pprempoly)
        !            90: {
        !            91:     int i;
        !            92:     HRESULT hresult;
        !            93:     IUnknown FAR* punk;
        !            94:     CRemPoly FAR* prempoly;
        !            95: 
        !            96: 
        !            97:     prempoly = new FAR CRemPoly();
        !            98:     if(prempoly == (CRemPoly FAR*)NULL){
        !            99:       hresult = ResultFromScode(E_OUTOFMEMORY);
        !           100:       goto LError;
        !           101:     }
        !           102:     prempoly->AddRef();
        !           103:       
        !           104:     // create an instance of the remote CPoly class.
        !           105:     //
        !           106:     IfMac(DbPrintf("CoCreateInstance(CLSID_CPoly)"));
        !           107:     hresult = CoCreateInstance(
        !           108:       clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void FAR* FAR*)&punk);
        !           109:     if(hresult != NOERROR){
        !           110:       IfMac(DbPrintf("CoCreateInstance() = 0x%x", hresult));
        !           111:       IfWin(MessageBox(NULL, "Unable to create polygon object", NULL, MB_OK));
        !           112:       goto LFreeCRemPoly;
        !           113:     }
        !           114: 
        !           115:     // were going to talk to this remote instance via IDispatch.
        !           116:     //
        !           117:     IfMac(DbPrintf("QueryInterface(IID_IDispatch)"));
        !           118:     hresult = punk->QueryInterface(
        !           119:       IID_IDispatch, (void FAR* FAR*)&prempoly->m_pdisp);
        !           120:     if(hresult != NOERROR){
        !           121:       IfMac(DbPrintf("QueryInterface(IID_IDispatch) = 0x%x", hresult));
        !           122:       IfWin(MessageBox(NULL, "Unable to QueryInterface to IDispatch", NULL, MB_OK));
        !           123:       goto LReleaseUnk;
        !           124:     }
        !           125: 
        !           126:     // We learn *all* the member IDs up front. A more sophisticated
        !           127:     // implementation might defer learning about the IDs for a given
        !           128:     // method until the first time the method is invoked, thereby
        !           129:     // amortizing the creation costs.
        !           130:     //
        !           131:     IfMac(DbPrintf("GetIDsOfNames()"));
        !           132:     for(i = 0; i < IMETH_CREMPOLY_MAX; ++i){
        !           133:       hresult = prempoly->m_pdisp->GetIDsOfNames(
        !           134:        IID_NULL,
        !           135:         &prempoly->m_rgszMethods[i],
        !           136:        1, LOCALE_USER_DEFAULT,
        !           137:        &prempoly->m_rgdispid[i]);
        !           138:       if(hresult != NOERROR){
        !           139:        IfMac(DbPrintf("GetIDsOfNames() = 0x%x", hresult));
        !           140:        IfWin(MessageBox(NULL, "Unrecognized member name", NULL, MB_OK));
        !           141:        goto LReleaseUnk;
        !           142:       }
        !           143:     }
        !           144: 
        !           145:     punk->Release();
        !           146: 
        !           147:     *pprempoly = prempoly;
        !           148: 
        !           149:     IfMac(DbPrintf("Object created."));
        !           150: 
        !           151:     return NOERROR;
        !           152: 
        !           153: LReleaseUnk:;
        !           154:     punk->Release();
        !           155: 
        !           156: LFreeCRemPoly:;
        !           157:     prempoly->Release();
        !           158: 
        !           159: LError:;
        !           160:     return hresult;
        !           161: }
        !           162: 
        !           163: 
        !           164: //---------------------------------------------------------------------
        !           165: //                     IUnknown methods
        !           166: //---------------------------------------------------------------------
        !           167: 
        !           168: 
        !           169: /***
        !           170: *HRESULT CRemPoly::QueryInterface(REFIID, void**)
        !           171: *
        !           172: *Purpose:
        !           173: *  Standard Ole2 implementation of QueryInterface. This class
        !           174: *  supports the IUnknown interface, and introduces a number of
        !           175: *  nonvirtual members.
        !           176: *
        !           177: *Entry:
        !           178: *  riid = reference to the requested interface id
        !           179: *
        !           180: *Exit:
        !           181: *  return value = HRESULT
        !           182: *  *ppv = pointer to the requested interface, if successful.
        !           183: *
        !           184: ***********************************************************************/
        !           185: STDMETHODIMP
        !           186: CRemPoly::QueryInterface(REFIID riid, void FAR* FAR* ppv)
        !           187: {
        !           188:     if(riid == IID_IUnknown){
        !           189:       *ppv = this;
        !           190:       AddRef();
        !           191:       return NOERROR;
        !           192:     }
        !           193:     return ResultFromScode(E_NOINTERFACE);
        !           194: }
        !           195: 
        !           196: 
        !           197: /***
        !           198: *unsigned long CRemPoly::AddRef(void)
        !           199: *
        !           200: *Purpose:
        !           201: *  Add a reference to the instance.
        !           202: *
        !           203: *Entry:
        !           204: *  None
        !           205: *
        !           206: *Exit:
        !           207: *  return value = unsigned long. The resulting reference count.
        !           208: *
        !           209: ***********************************************************************/
        !           210: STDMETHODIMP_(unsigned long)
        !           211: CRemPoly::AddRef(void)
        !           212: {
        !           213:     return ++m_refs;
        !           214: }
        !           215: 
        !           216: 
        !           217: /***
        !           218: *unsigned long CRemPoly::Release(void)
        !           219: *
        !           220: *Purpose:
        !           221: *  Release a reference to the instance. If the reference count goes
        !           222: *  to zero, delete the instance.
        !           223: *
        !           224: *Entry:
        !           225: *  None
        !           226: *
        !           227: *Exit:
        !           228: *  return value = unsigned long. The resulting reference count.
        !           229: *
        !           230: ***********************************************************************/
        !           231: STDMETHODIMP_(unsigned long)
        !           232: CRemPoly::Release(void)
        !           233: {
        !           234:     if(--m_refs == 0){
        !           235:       if(m_pdisp != (IDispatch FAR*)NULL){
        !           236:         m_pdisp->Release();
        !           237:       }
        !           238:       delete this;
        !           239:       return 0;
        !           240:     }
        !           241:     return m_refs;
        !           242: }
        !           243: 
        !           244: 
        !           245: //---------------------------------------------------------------------
        !           246: //                    Introduced methods
        !           247: //---------------------------------------------------------------------
        !           248: 
        !           249: 
        !           250: /*
        !           251:  * Each of these methods is simply a cover for an IDispatch Invocation
        !           252:  * of the actual method on the remote CPoly class. This allows CRemPoly
        !           253:  * to present an interface that looks and acts just like the CPoly
        !           254:  * object, even though the actual work is being done in another process.
        !           255:  *
        !           256:  */
        !           257: 
        !           258: /***
        !           259: *HRESULT CRemPoly::Draw(void)
        !           260: *
        !           261: *Purpose:
        !           262: *  Invoke the Draw method on the remote CPoly instance.
        !           263: *
        !           264: *Entry:
        !           265: *  None
        !           266: *
        !           267: *Exit:
        !           268: *  return value = HRESULT
        !           269: *
        !           270: ***********************************************************************/
        !           271: HRESULT
        !           272: CRemPoly::Draw()
        !           273: {
        !           274:     return m_pdisp->Invoke(
        !           275:       m_rgdispid[IMETH_CREMPOLY_DRAW],
        !           276:       IID_NULL,
        !           277:       LOCALE_USER_DEFAULT,
        !           278:       DISPATCH_METHOD,
        !           279:       &g_dispparamsNoArgs, NULL, NULL, NULL);
        !           280: }
        !           281: 
        !           282: 
        !           283: /***
        !           284: *HRESULT CRemPoly::Dump(void)
        !           285: *
        !           286: *Purpose:
        !           287: *  Invoke the Dump() method on the remote CPoly instance. This method
        !           288: *  dumps the contained CPoints and writes the properties of the remote
        !           289: *  CPoly instance to the debug window.
        !           290: *
        !           291: *Entry:
        !           292: *  None
        !           293: *
        !           294: *Exit:
        !           295: *  return value = HRESULT
        !           296: *
        !           297: ***********************************************************************/
        !           298: HRESULT
        !           299: CRemPoly::Dump()
        !           300: {
        !           301:     return m_pdisp->Invoke(
        !           302:       m_rgdispid[IMETH_CREMPOLY_DUMP],
        !           303:       IID_NULL,
        !           304:       LOCALE_USER_DEFAULT,
        !           305:       DISPATCH_METHOD,
        !           306:       &g_dispparamsNoArgs, NULL, NULL, NULL);
        !           307: }
        !           308: 
        !           309: 
        !           310: /***
        !           311: *HRESULT CRemPoly::Reset(void)
        !           312: *
        !           313: *Purpose:
        !           314: *  Invoke the Reset() method on the remote CPoly instance. The Reset()
        !           315: *  method causes the remote CPoly to release all contained CPoints.
        !           316: *
        !           317: *Entry:
        !           318: *  None
        !           319: *
        !           320: *Exit:
        !           321: *  return value = HRESULT
        !           322: *
        !           323: ***********************************************************************/
        !           324: HRESULT
        !           325: CRemPoly::Reset()
        !           326: {
        !           327:     return m_pdisp->Invoke(
        !           328:       m_rgdispid[IMETH_CREMPOLY_RESET],
        !           329:       IID_NULL,
        !           330:       LOCALE_USER_DEFAULT,
        !           331:       DISPATCH_METHOD,
        !           332:       &g_dispparamsNoArgs, NULL, NULL, NULL);
        !           333: }
        !           334: 
        !           335: 
        !           336: /***
        !           337: *HRESULT CRemPoly::AddPoint(short, short)
        !           338: *
        !           339: *Purpose:
        !           340: *  Invoke the AddPoint method in the remote CPoly object to add a
        !           341: *  new point with the given coordinates to this instance.
        !           342: *
        !           343: *Entry:
        !           344: *  x,y = the x and y coordinates of the new point.
        !           345: *
        !           346: *Exit:
        !           347: *  return value = HRESULT
        !           348: *
        !           349: ***********************************************************************/
        !           350: HRESULT
        !           351: CRemPoly::AddPoint(short x, short y)
        !           352: {
        !           353:     HRESULT hresult;
        !           354:     VARIANTARG varg[2];
        !           355:     DISPPARAMS dispparams;
        !           356: 
        !           357:     V_VT(&varg[0]) = VT_I2;
        !           358:     V_I2(&varg[0]) = y;
        !           359: 
        !           360:     V_VT(&varg[1]) = VT_I2;
        !           361:     V_I2(&varg[1]) = x;
        !           362: 
        !           363:     dispparams.cArgs = 2;
        !           364:     dispparams.rgvarg = varg;
        !           365:     dispparams.cNamedArgs = 0;
        !           366:     dispparams.rgdispidNamedArgs = NULL;
        !           367: 
        !           368:     hresult = m_pdisp->Invoke(
        !           369:       m_rgdispid[IMETH_CREMPOLY_ADDPOINT],
        !           370:       IID_NULL,
        !           371:       LOCALE_USER_DEFAULT,
        !           372:       DISPATCH_METHOD,
        !           373:       &dispparams, NULL, NULL, NULL);
        !           374: 
        !           375:     return hresult;
        !           376: }
        !           377: 
        !           378: 
        !           379: /***
        !           380: *HRESULT CRemPoly::EnumPoints(IEnumVARIANT**)
        !           381: *Purpose:
        !           382: *  Inoke the EnumPoints() method in the remote object to
        !           383: *  get a enumerator for the points contained in the current poly.
        !           384: *
        !           385: *Entry:
        !           386: *  None
        !           387: *
        !           388: *Exit:
        !           389: *  return value = HRESULT
        !           390: *
        !           391: *  *ppenum = pointer to the point enumerator
        !           392: *
        !           393: ***********************************************************************/
        !           394: HRESULT
        !           395: CRemPoly::EnumPoints(IEnumVARIANT FAR* FAR* ppenum)
        !           396: {
        !           397:     HRESULT hresult;
        !           398:     IEnumVARIANT FAR* penum;
        !           399:     VARIANT varResult, FAR* pvarResult;
        !           400: 
        !           401: 
        !           402:     pvarResult = &varResult;
        !           403:     VariantInit(pvarResult);
        !           404:     hresult = m_pdisp->Invoke(
        !           405:       m_rgdispid[IMETH_CREMPOLY_ENUMPOINTS],
        !           406:       IID_NULL,
        !           407:       LOCALE_USER_DEFAULT,
        !           408:       DISPATCH_METHOD,
        !           409:       &g_dispparamsNoArgs, pvarResult, NULL, NULL);
        !           410: 
        !           411:     if(hresult != NOERROR)
        !           412:       return hresult;
        !           413: 
        !           414:     if(V_VT(pvarResult) != VT_UNKNOWN)
        !           415:       return ResultFromScode(E_FAIL);
        !           416: 
        !           417:     hresult = V_UNKNOWN(pvarResult)->QueryInterface(
        !           418:       IID_IEnumVARIANT, (void FAR* FAR*)&penum);
        !           419: 
        !           420:     if(hresult == NOERROR)
        !           421:       *ppenum = penum;
        !           422: 
        !           423:     VariantClear(pvarResult);
        !           424: 
        !           425:     return NOERROR;
        !           426: }
        !           427: 
        !           428: 
        !           429: /***
        !           430: *HRESULT CRemPoly::GetXOrigin(short*)
        !           431: *
        !           432: *Purpose:
        !           433: *  Invoke the GetXOrigin() method on the remote object to extract
        !           434: *  the current value of the XOrigin property.
        !           435: *
        !           436: *Entry:
        !           437: *  None
        !           438: *
        !           439: *Exit:
        !           440: *  return value = HRESULT
        !           441: *
        !           442: *  *pxorg = the current X origin of the polygon.
        !           443: *
        !           444: ***********************************************************************/
        !           445: HRESULT
        !           446: CRemPoly::GetXOrigin(short FAR* pxorg)
        !           447: {
        !           448:     HRESULT hresult;
        !           449:     VARIANT varResult;
        !           450: 
        !           451:     VariantInit(&varResult);
        !           452:     hresult = m_pdisp->Invoke(
        !           453:       m_rgdispid[IMETH_CREMPOLY_GETXORIGIN],
        !           454:       IID_NULL,
        !           455:       LOCALE_USER_DEFAULT,
        !           456:       DISPATCH_METHOD,
        !           457:       &g_dispparamsNoArgs, &varResult, NULL, NULL);
        !           458: 
        !           459:     if(hresult != NOERROR)
        !           460:       return hresult;
        !           461: 
        !           462:     *pxorg = V_I2(&varResult);
        !           463: 
        !           464:     return NOERROR;
        !           465: }
        !           466: 
        !           467: 
        !           468: /***
        !           469: *HRESULT CRemPoly::SetXOrigin(short)
        !           470: *
        !           471: *Purpose:
        !           472: *  Invoke the SetXOrigin method on the remote object to set the
        !           473: *  XOrigin property of the polygon to the given value.
        !           474: *
        !           475: *Entry:
        !           476: *  xorg = the new X origin
        !           477: *
        !           478: *Exit:
        !           479: *  return value = HRESULT
        !           480: *
        !           481: ***********************************************************************/
        !           482: HRESULT
        !           483: CRemPoly::SetXOrigin(short xorg)
        !           484: {
        !           485:     VARIANTARG varg;
        !           486:     DISPPARAMS dispparams;
        !           487: 
        !           488: 
        !           489:     V_VT(&varg) = VT_I2;
        !           490:     V_I2(&varg) = xorg;
        !           491: 
        !           492:     dispparams.cArgs = 1;
        !           493:     dispparams.cNamedArgs = 0;
        !           494:     dispparams.rgvarg = &varg;
        !           495: 
        !           496:     return m_pdisp->Invoke(
        !           497:       m_rgdispid[IMETH_CREMPOLY_SETXORIGIN],
        !           498:       IID_NULL,
        !           499:       LOCALE_USER_DEFAULT,
        !           500:       DISPATCH_METHOD,
        !           501:       &dispparams, NULL, NULL, NULL);
        !           502: }
        !           503: 
        !           504: 
        !           505: /***
        !           506: *HRESULT CRemPoly::GetYOrigin(short*)
        !           507: *
        !           508: *Purpose:
        !           509: *  Invoke the GetYOrigin() method on the remote object to extract
        !           510: *  the current value of the YOrigin property.
        !           511: *
        !           512: *Entry:
        !           513: *  None
        !           514: *
        !           515: *Exit:
        !           516: *  return value = HRESULT
        !           517: *
        !           518: *  *pyorg = the current Y origin of the polygon
        !           519: *
        !           520: ***********************************************************************/
        !           521: HRESULT
        !           522: CRemPoly::GetYOrigin(short FAR* pyorg)
        !           523: {
        !           524:     HRESULT hresult;
        !           525:     VARIANT varResult;
        !           526: 
        !           527: 
        !           528:     VariantInit(&varResult);
        !           529:     hresult = m_pdisp->Invoke(
        !           530:       m_rgdispid[IMETH_CREMPOLY_GETYORIGIN],
        !           531:       IID_NULL,
        !           532:       LOCALE_USER_DEFAULT,
        !           533:       DISPATCH_METHOD,
        !           534:       &g_dispparamsNoArgs, &varResult, NULL, NULL);
        !           535: 
        !           536:     if(hresult != NOERROR)
        !           537:       return hresult;
        !           538: 
        !           539:     *pyorg = V_I2(&varResult);
        !           540: 
        !           541:     return hresult;
        !           542: }
        !           543: 
        !           544: 
        !           545: /***
        !           546: *HRESULT CRemPoly::SetYOrigin(short)
        !           547: *
        !           548: *Purpose:
        !           549: *  Invoke the SetYOrigin method on the remote object to set the
        !           550: *  YOrigin property of the polygon to the given value.
        !           551: *
        !           552: *Entry:
        !           553: *  yorg = the new Y origin
        !           554: *
        !           555: *Exit:
        !           556: *  return value = HRESULT
        !           557: *
        !           558: ***********************************************************************/
        !           559: HRESULT
        !           560: CRemPoly::SetYOrigin(short yorg)
        !           561: {
        !           562:     VARIANTARG varg;
        !           563:     DISPPARAMS dispparams;
        !           564: 
        !           565:     V_VT(&varg) = VT_I2;
        !           566:     V_I2(&varg) = yorg;
        !           567: 
        !           568:     dispparams.cArgs = 1;
        !           569:     dispparams.cNamedArgs = 0;
        !           570:     dispparams.rgvarg = &varg;
        !           571: 
        !           572:     return m_pdisp->Invoke(
        !           573:       m_rgdispid[IMETH_CREMPOLY_SETYORIGIN],
        !           574:       IID_NULL,
        !           575:       LOCALE_USER_DEFAULT,
        !           576:       DISPATCH_METHOD,
        !           577:       &dispparams, NULL, NULL, NULL);
        !           578: }
        !           579: 
        !           580: 
        !           581: /***
        !           582: *HRESULT CRemPoly::GetWidth(short*)
        !           583: *
        !           584: *Purpose:
        !           585: *  Invoke the GetWidth() method on the remote object to extract
        !           586: *  the current value of the line width property.
        !           587: *
        !           588: *Entry:
        !           589: *  None
        !           590: *
        !           591: *Exit:
        !           592: *  return value = HRESULT
        !           593: *
        !           594: *  *pwidth = short, the current line width of the polygon
        !           595: *
        !           596: ***********************************************************************/
        !           597: HRESULT
        !           598: CRemPoly::GetWidth(short FAR* pwidth)
        !           599: {
        !           600:     HRESULT hresult;
        !           601:     VARIANT varResult;
        !           602: 
        !           603: 
        !           604:     hresult = m_pdisp->Invoke(
        !           605:       m_rgdispid[IMETH_CREMPOLY_GETWIDTH],
        !           606:       IID_NULL,
        !           607:       LOCALE_USER_DEFAULT,
        !           608:       DISPATCH_METHOD,
        !           609:       &g_dispparamsNoArgs, &varResult, NULL, NULL);
        !           610: 
        !           611:     if(hresult != NOERROR)
        !           612:       return hresult;
        !           613: 
        !           614:     *pwidth = V_I2(&varResult);
        !           615: 
        !           616:     return NOERROR;
        !           617: }
        !           618: 
        !           619: 
        !           620: /***
        !           621: *HRESULT CRemPoly::SetWidth(short)
        !           622: *
        !           623: *Purpose:
        !           624: *  Invoke the SetWidth method on the remote object to set the
        !           625: *  line width property of the polygon to the given value.
        !           626: *
        !           627: *Entry:
        !           628: *  width = the new value for the line width property.
        !           629: *
        !           630: *Exit:
        !           631: *  return value = HRESULT
        !           632: *
        !           633: ***********************************************************************/
        !           634: HRESULT
        !           635: CRemPoly::SetWidth(short width)
        !           636: {
        !           637:     VARIANTARG varg;
        !           638:     DISPPARAMS dispparams;
        !           639: 
        !           640: 
        !           641:     V_VT(&varg) = VT_I2;
        !           642:     V_I2(&varg) = width;
        !           643: 
        !           644:     dispparams.cArgs = 1;
        !           645:     dispparams.cNamedArgs = 0;
        !           646:     dispparams.rgvarg = &varg;
        !           647: 
        !           648:     return m_pdisp->Invoke(
        !           649:       m_rgdispid[IMETH_CREMPOLY_SETWIDTH],
        !           650:       IID_NULL,
        !           651:       LOCALE_USER_DEFAULT,
        !           652:       DISPATCH_METHOD,
        !           653:       &dispparams, NULL, NULL, NULL);
        !           654: }
        !           655: 
        !           656: 
        !           657: HRESULT CRemPoly::get_red(short FAR* psRed)
        !           658: {
        !           659:     return get_i2(m_rgdispid[IMETH_CREMPOLY_GETRED], psRed);
        !           660: }
        !           661: 
        !           662: HRESULT CRemPoly::set_red(short sRed)
        !           663: {
        !           664:     return set_i2(m_rgdispid[IMETH_CREMPOLY_SETRED], sRed);
        !           665: }
        !           666: 
        !           667: 
        !           668: HRESULT CRemPoly::get_green(short FAR* psGreen)
        !           669: {
        !           670:     return get_i2(m_rgdispid[IMETH_CREMPOLY_GETGREEN], psGreen);
        !           671: }
        !           672: 
        !           673: HRESULT CRemPoly::set_green(short sGreen)
        !           674: {
        !           675:     return set_i2(m_rgdispid[IMETH_CREMPOLY_SETGREEN], sGreen);
        !           676: }
        !           677: 
        !           678: 
        !           679: HRESULT CRemPoly::get_blue(short FAR* psBlue)
        !           680: {
        !           681:     return get_i2(m_rgdispid[IMETH_CREMPOLY_GETBLUE], psBlue);
        !           682: }
        !           683: 
        !           684: HRESULT CRemPoly::set_blue(short sBlue)
        !           685: {
        !           686:     return set_i2(m_rgdispid[IMETH_CREMPOLY_SETBLUE], sBlue);
        !           687: }
        !           688: 
        !           689: HRESULT
        !           690: CRemPoly::get_i2(DISPID dispid, short FAR* ps)
        !           691: {
        !           692:     HRESULT hresult;
        !           693:     VARIANT varResult;
        !           694: 
        !           695:     VariantInit(&varResult);
        !           696: 
        !           697:     hresult = m_pdisp->Invoke(
        !           698:       dispid,
        !           699:       IID_NULL,
        !           700:       LOCALE_SYSTEM_DEFAULT,
        !           701:       DISPATCH_METHOD,
        !           702:       &g_dispparamsNoArgs,
        !           703:       &varResult, NULL, NULL);
        !           704: 
        !           705:     if(hresult != NOERROR)
        !           706:       return hresult;
        !           707: 
        !           708:     hresult = VariantChangeType(&varResult, &varResult, 0, VT_I2);
        !           709:     if(hresult != NOERROR){
        !           710:       VariantClear(&varResult);
        !           711:       return hresult;
        !           712:     }
        !           713: 
        !           714:     *ps = V_I2(&varResult);
        !           715:     return NOERROR;
        !           716: }
        !           717: 
        !           718: HRESULT
        !           719: CRemPoly::set_i2(DISPID dispid, short s)
        !           720: {
        !           721:     VARIANTARG varg;
        !           722:     DISPPARAMS dispparams;
        !           723: 
        !           724:     V_VT(&varg) = VT_I2;
        !           725:     V_I2(&varg) = s;
        !           726: 
        !           727:     dispparams.cArgs = 1;
        !           728:     dispparams.cNamedArgs = 0;
        !           729:     dispparams.rgvarg = &varg;
        !           730: 
        !           731:     return m_pdisp->Invoke(
        !           732:       dispid,
        !           733:       IID_NULL,
        !           734:       LOCALE_SYSTEM_DEFAULT,
        !           735:       DISPATCH_METHOD,
        !           736:       &dispparams, NULL, NULL, NULL);
        !           737: }
        !           738: 
        !           739: 
        !           740: /***
        !           741: *void DoPoly(CLSID) 
        !           742: *
        !           743: *Purpose:
        !           744: *  This function simply exercises our CRemPoly class by creating an
        !           745: *  instance and invoking a number of its methods.
        !           746: *
        !           747: *Entry:
        !           748: *  None
        !           749: *
        !           750: *Exit:
        !           751: *  None
        !           752: *
        !           753: ***********************************************************************/
        !           754: STDAPI
        !           755: DoPoly(CLSID clsid)
        !           756: {
        !           757:     HRESULT hr;
        !           758:     int numpoly, i, j;
        !           759: 
        !           760: static struct {
        !           761:     short x;
        !           762:     short y;
        !           763: } rgptPoly[] = {
        !           764:       { 25,   0}
        !           765:     , { 75,   0}
        !           766:     , {100,  25}
        !           767:     , {100,  75}
        !           768:     , { 75, 100}
        !           769:     , { 25, 100}
        !           770:     , {  0,  75}
        !           771:     , {  0,  25}
        !           772: };
        !           773: 
        !           774: static struct {
        !           775:     short red;
        !           776:     short green;
        !           777:     short blue;
        !           778: } rgrgbColors[] = {
        !           779: #ifdef _MAC
        !           780:       {     0,      0,      0}
        !           781:     , {     0,      0, 0x7fff}
        !           782:     , {     0, 0x7fff,      0}
        !           783:     , {0x7fff,      0,      0}
        !           784:     , {0x7fff,      0, 0x7fff}
        !           785:     , {0x7fff, 0x7fff,      0}
        !           786:     , {0x7fff, 0x7fff, 0x7fff}
        !           787: #else
        !           788:       {  0,   0,   0}
        !           789:     , {  0,   0, 127}
        !           790:     , {  0, 127,   0}
        !           791:     , {127,   0,   0}
        !           792:     , {127,   0, 127}
        !           793:     , {127, 127,   0}
        !           794:     , {127, 127, 127}
        !           795: #endif
        !           796: };
        !           797: 
        !           798:     CRemPoly FAR* rgprempoly[DIM(rgrgbColors)];
        !           799: 
        !           800:     numpoly = DIM(rgprempoly);
        !           801: 
        !           802:     // init
        !           803:     for(i = 0; i < numpoly; ++i)
        !           804:       rgprempoly[i] = (CRemPoly FAR*)NULL;
        !           805: 
        !           806:     for(i = 0; i < numpoly; ++i){
        !           807:       hr = CRemPoly::Create(clsid, &rgprempoly[i]);
        !           808:       if(hr != NOERROR)
        !           809:         goto LError0;
        !           810:       IfMac(DbPrintf("CRemPoly::Create()"));
        !           811: 
        !           812:       for(j = 0; j < DIM(rgptPoly); ++j){
        !           813:         short x = rgptPoly[j].x;
        !           814:        short y = rgptPoly[j].y;
        !           815:         IfMac(DbPrintf("CRemPoly::AddPoint(%d,%d)", x, y));
        !           816:         hr = rgprempoly[i]->AddPoint(x, y);
        !           817:        ASSERT(hr == NOERROR);
        !           818:       }
        !           819: 
        !           820:       for(j = 0; j < DIM(rgrgbColors); ++j){
        !           821:         hr = rgprempoly[i]->SetWidth(i + j);
        !           822:        ASSERT(hr == NOERROR);
        !           823:        IfMac(DbPrintf("CRemPoly::SetWidth()"));
        !           824: 
        !           825:         hr = rgprempoly[i]->set_red(rgrgbColors[j].red);
        !           826:        ASSERT(hr == NOERROR);
        !           827:        IfMac(DbPrintf("CRemPoly::set_red()"));
        !           828: 
        !           829:         hr = rgprempoly[i]->set_green(rgrgbColors[j].green);
        !           830:        ASSERT(hr == NOERROR);
        !           831:        IfMac(DbPrintf("CRemPoly::set_green()"));
        !           832: 
        !           833:         hr = rgprempoly[i]->set_blue(rgrgbColors[j].blue);
        !           834:        ASSERT(hr == NOERROR);
        !           835:        IfMac(DbPrintf("CRemPoly::set_blue()"));
        !           836: 
        !           837:         hr = rgprempoly[i]->SetXOrigin((2*i) + j << 4);
        !           838:        ASSERT(hr == NOERROR);
        !           839:        IfMac(DbPrintf("CRemPoly::SetXOrigin()"));
        !           840: 
        !           841:         hr = rgprempoly[i]->SetYOrigin(j << 4);
        !           842:        ASSERT(hr == NOERROR);
        !           843:        IfMac(DbPrintf("CRemPoly::SetYOrigin()"));
        !           844: 
        !           845:         hr = rgprempoly[i]->Draw();
        !           846:        ASSERT(hr == NOERROR);
        !           847:        IfMac(DbPrintf("CRemPoly::Draw()"));
        !           848:       }
        !           849:     }
        !           850: 
        !           851:     hr = NOERROR;
        !           852: 
        !           853: LError0:;
        !           854:     for(i = 0; i < numpoly; ++i){
        !           855:       if(rgprempoly[i] != (CRemPoly FAR*)NULL){
        !           856:        rgprempoly[i]->Release();
        !           857:       }
        !           858:     }
        !           859: 
        !           860:     return hr;
        !           861: }
        !           862: 

unix.superglobalmegacorp.com

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