KOALA.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * KOALA.H
  3.  * Koala Object with Custom Interface, Chapter 6
  4.  *
  5.  * Classes that implement the CKoala object with a custom interface
  6.  * to demonstrate local/remote transparency.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14. #ifndef _KOALA_H_
  15. #define _KOALA_H_
  16. #define CHAPTER6
  17. #include <inole.h>
  18. #include <ianimal.h>
  19. #include <ikoala.h>
  20. //KOALA.CPP
  21. //CHAPTER6MOD
  22. class CImpIAnimal;
  23. typedef CImpIAnimal *PCImpIAnimal;
  24. class CImpIKoala;
  25. typedef CImpIKoala *PCImpIKoala;
  26. //End CHAPTER6MOD
  27. class CKoala : public IUnknown
  28.     {
  29.     //CHAPTER6MOD
  30.     friend class CImpIAnimal;
  31.     friend class CImpIKoala;
  32.     //End CHAPTER6MOD
  33.     protected:
  34.         ULONG           m_cRef;         //Object reference count
  35.         LPUNKNOWN       m_pUnkOuter;    //Controlling unknown
  36.         PFNDESTROYED    m_pfnDestroy;   //To call on closure
  37.         //CHAPTER6MOD
  38.         PCImpIAnimal    m_pImpIAnimal;  //Our interfaces
  39.         PCImpIKoala     m_pImpIKoala;
  40.         BOOL            m_fJustAte;
  41.         short           m_cSleepAfterEat;
  42.         //CHAPTER6MOD
  43.     public:
  44.         CKoala(LPUNKNOWN, PFNDESTROYED);
  45.         ~CKoala(void);
  46.         BOOL Init(void);
  47.         //Non-delegating object IUnknown
  48.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  49.         STDMETHODIMP_(ULONG) AddRef(void);
  50.         STDMETHODIMP_(ULONG) Release(void);
  51.     };
  52. typedef CKoala *PCKoala;
  53. //CHAPTER6MOD
  54. //IAnimal interface implementation
  55. class CImpIAnimal : public IAnimal
  56.     {
  57.     protected:
  58.         ULONG           m_cRef;      //Interface reference count
  59.         PCKoala         m_pObj;      //Back pointer to the object
  60.         LPUNKNOWN       m_pUnkOuter; //For delegation
  61.     public:
  62.         CImpIAnimal(PCKoala, LPUNKNOWN);
  63.         ~CImpIAnimal(void);
  64.         //IUnknown members
  65.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  66.         STDMETHODIMP_(ULONG) AddRef(void);
  67.         STDMETHODIMP_(ULONG) Release(void);
  68.         //IAnimal members
  69.         STDMETHODIMP Eat(LPTSTR, LPTSTR, short);
  70.         STDMETHODIMP Sleep(short *);
  71.         STDMETHODIMP Procreate(short *);
  72.         STDMETHODIMP WhatKindOfAnimal(IID *);
  73.     };
  74. //IKoala interface implementation
  75. class CImpIKoala : public IKoala
  76.     {
  77.     protected:
  78.         ULONG           m_cRef;      //Interface reference count
  79.         PCKoala         m_pObj;      //Back pointer to the object
  80.         LPUNKNOWN       m_pUnkOuter; //For delegation
  81.     public:
  82.         CImpIKoala(PCKoala, LPUNKNOWN);
  83.         ~CImpIKoala(void);
  84.         //IUnknown members
  85.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  86.         STDMETHODIMP_(ULONG) AddRef(void);
  87.         STDMETHODIMP_(ULONG) Release(void);
  88.         //IKoala members
  89.         STDMETHODIMP ClimbEucalyptusTree(short);
  90.         STDMETHODIMP PouchOpensDown(void);
  91.         STDMETHODIMP SleepAfterEating(short);
  92.     };
  93. //End CHAPTER6MOD
  94. #endif //_KOALA_H_