Essential COM

- , . ( ), , , . , - C++. , ; O - (host machine), , , . .

. ( CLSID ), , CLSID. , (brokers) , , - . , , . , I . I :

 class GorillaClass : public IApe {   public:       // class objects are singletons, so don't delete       //            ,       //              IMPLEMENT_UNKNOWN_NO_DELETE (GorillaClass)     BEGIN_INTERFACE_TABLE(GorillaClass)        IMPLEMENTS_INTERFACE(IApe)     END_INTERFACE_TABLE()       // IApe methods       //   IApe     STDMETHODIMP EatBanana(void);     STDMETHODIMP SwingFromTree(void);     STDMETHODIMP get_Weight(long *plbs); }; 

C++ ( ), (gorilla). . , , , , . , IApe, , / . C++: . C++, , IApe:

 class Gorilla : public IApe {   public:       // Instances are heap-based, so delete when done        //        ,              IMPLEMENT_UNKNOWN()      BEGIN_INTERFACE_TABLE()       IMPLEMENTS_INTERFACE(IApe)      END_INTERFACE_TABLE()        // IApe methods        //   IApe      STDMETHODIMP EatBanana(void);     STDMETHODIMP SwingFromTree(void);     STDMETHODIMP get_Weight(long *plbs): }; 

, Gorilla:

 [object, uuid(753A8AAC-A7FF-11d0-8C30-0080C73925BA)] interface IApeClass : IUnknown {   HRESULT CreateApe([out, retval] IApe **ppApe);   HRESULT GetApe([in] long nApeID, [out, retval] IApe **ppApe);   [propget] HRESULT AverageWeight([out, retval] long *plbs); } 

, IApeClass ++- Gorilla ( CreateApe), ( integer) ( GetApe):

 class GorillaClass : public IApeClass {   public:     IMPLEMENT_UNKNOWN_NO_DELETE(GorillaClass)      BEGIN_INTERFACE_TABLE(GorillaClass)       IMPLEMENTS_INTERFACE(IApeClass)      END_INTERFACE_TABLE()     STDMETHODIMP CreateApe(Ape **ppApe) {          if ((*ppApe = new Gorilla) == 0)              return E_OUTOFMEMORY;         (*ppApe)->AddRef();         return S_OK;     }     STDMETHODIMP GetApe(long nApeID, IApe **ppApe) {        // assume that a table of well-known gorillas is        // being maintained somewhere else        //  ,                  //    -         extern Gorilla *g_rgWellKnownGorillas[];       extern int g_nMaxGorillas;         // assert that nApeID is a valid index        //  ,   nApeID -          *  = 0;       if (nApeID > g_nMaxGorillas || nApeID < 0)            return E_INVALIDARG;       // assume that the ID is simply the index into the table        //  ,   ID -                if ((*ppApe = g_rgWellKnownGorillas[nApeID]) == 0)            return E_INVALIDARG;       (*ppApe)->AddRef();       return S_OK;     }     STDMETHODIMP get_AverageWeight(long *plbs) {        extern  *g_rgWellKnownGorillas[];       extern int g_nMaxGorillas;       *plbs = 0;        long lbs;       for (int i = 0; i < g_nMaxGorillas; i++) {          g_rgWellKnownGorillas[i]->get_Weight(&lbs);         *plbs += lbs;       }       // assumes g_nMaxGorillas is non-zero        //  ,   g_nMaxGorillas          *plbs /= g_nMaxGorillas;       return S_OK;     }  }; 

, , Gorilla, - (agent).



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