QueryInterface

QueryInterface

, QueryInterface , , . ,

 QI(A)->A  

.

 . 4.4. queryinterface

. 4.4 :

 void AssertReflexive(ICar *pCar)  {     if (pCar) {          ICar *pCar2 = 0;           // request same type of interface            //                    HRESULT hr = pCar->QueryInterface(IID_ICar, (void**)&pCar2);           // if the following assertion fails, pCar            // did not point to a valid   object            //        ,   pCar            //                      assert(SUCCEEDED(hr));         pCar2->Release();     }  } 

, ICar QueryInterface ICar ICar. , :

 extern void GetCar(ICar **ppcar); extern void UseVehicle(IVehicle *pv); ICar *pCar; GetCar(&pCar); UseVehicle(pCar); // ICar-ness is syntactically lost  // ICar-       void UseVehicle(IVehicle *pv)  {      ICar *pCar = 0;       // try to regain syntactic ICar-ness        //       ICar-       HRESULT hr = pv->QueryInterface(IID_ICar, (void**)&pCar); } 

, UseVehicle, , ICar, , (counterintuitive), .

, QueryInterface , , , " / " QueryInterface. , ( ) (explicit) . . 4.5 . , , .

 . 4.5.     queryinterface



Suschnost' tehnologii SOM
Essential COM
ISBN: 0201634465
EAN: 2147483647
Year: N/A
Pages: 103
Authors: Don Box

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net