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

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * KOALA.H
  3.  * Koala Custom Marshaling Proxy Chapter 6
  4.  *
  5.  * Classes that implement the CKoala object exposed from this
  6.  * proxy server that communicates with a local Koala through
  7.  * custom marshaling.
  8.  *
  9.  * Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved
  10.  *
  11.  * Kraig Brockschmidt, Microsoft
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15. #ifndef _KOALA_H_
  16. #define _KOALA_H_
  17. #define CHAPTER6
  18. #include <inole.h>
  19. #ifdef WIN32
  20. #include <ianimal.h>
  21. #include <ikoala.h>
  22. #else
  23. //Non-MIDL generated versions
  24. #include <ianim16.h>
  25. #include <ikoala16.h>
  26. #endif
  27. /*
  28.  * Marshaling packet data structure as used by our IMarshal.
  29.  * This is duplicated in ..ekoala5koala.h.
  30.  */
  31. typedef struct
  32.     {
  33.     HWND        hWnd;       //Message window
  34.     } KOALAMARSHAL, *PKOALAMARSHAL;
  35. //Intertask messages, duplicated in ..ekoala5koala.h.
  36. #define MSG_RELEASE             1000
  37. #define MSG_EAT                 1001
  38. #define MSG_SLEEP               1002
  39. #define MSG_PROCREATE           1003
  40. #define MSG_SLEEPAFTEREATING    1004
  41. //KOALA.CPP
  42. class CImpIAnimal;
  43. typedef CImpIAnimal *PCImpIAnimal;
  44. class CImpIKoala;
  45. typedef CImpIKoala *PCImpIKoala;
  46. class CImpIMarshal;
  47. typedef CImpIMarshal *PCImpIMarshal;
  48. class CKoala : public IUnknown
  49.     {
  50.     friend class CImpIAnimal;
  51.     friend class CImpIKoala;
  52.     friend class CImpIMarshal;
  53.     protected:
  54.         ULONG           m_cRef;         //Object reference count
  55.         LPUNKNOWN       m_pUnkOuter;    //Controlling unknown
  56.         PFNDESTROYED    m_pfnDestroy;   //To call on closure
  57.         PCImpIAnimal    m_pImpIAnimal;  //Our interfaces
  58.         PCImpIKoala     m_pImpIKoala;
  59.         PCImpIMarshal   m_pImpIMarshal;
  60.         BOOL            m_fJustAte;
  61.         short           m_cSleepAfterEat;
  62.         HWND            m_hWndLocal;    //Local object
  63.     public:
  64.         CKoala(LPUNKNOWN, PFNDESTROYED);
  65.         ~CKoala(void);
  66.         BOOL    Init(void);
  67.         DWORD   CallLocal(UINT, LPARAM, BOOL);
  68.         //Non-delegating object IUnknown
  69.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  70.         STDMETHODIMP_(ULONG) AddRef(void);
  71.         STDMETHODIMP_(ULONG) Release(void);
  72.     };
  73. typedef CKoala *PCKoala;
  74. //IAnimal interface implementation
  75. class CImpIAnimal : public IAnimal
  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.         CImpIAnimal(PCKoala, LPUNKNOWN);
  83.         ~CImpIAnimal(void);
  84.         //IUnknown members
  85.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  86.         STDMETHODIMP_(ULONG) AddRef(void);
  87.         STDMETHODIMP_(ULONG) Release(void);
  88.         //IAnimal members
  89.         STDMETHODIMP Eat(LPTSTR, LPTSTR, short);
  90.         STDMETHODIMP Sleep(short *);
  91.         STDMETHODIMP Procreate(short *);
  92.         STDMETHODIMP WhatKindOfAnimal(IID *);
  93.     };
  94. //IKoala interface implementation
  95. class CImpIKoala : public IKoala
  96.     {
  97.     protected:
  98.         ULONG           m_cRef;      //Interface reference count
  99.         PCKoala         m_pObj;      //Back pointer to the object
  100.         LPUNKNOWN       m_pUnkOuter; //For delegation
  101.     public:
  102.         CImpIKoala(PCKoala, LPUNKNOWN);
  103.         ~CImpIKoala(void);
  104.         //IUnknown members
  105.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  106.         STDMETHODIMP_(ULONG) AddRef(void);
  107.         STDMETHODIMP_(ULONG) Release(void);
  108.         //IKoala members
  109.         STDMETHODIMP ClimbEucalyptusTree(short);
  110.         STDMETHODIMP PouchOpensDown(void);
  111.         STDMETHODIMP SleepAfterEating(short);
  112.     };
  113. class CImpIMarshal : public IMarshal
  114.     {
  115.     protected:
  116.         ULONG           m_cRef;      //Interface reference count
  117.         PCKoala         m_pObj;      //Back pointer to the object
  118.         LPUNKNOWN       m_pUnkOuter; //For delegation
  119.     public:
  120.         CImpIMarshal(PCKoala, LPUNKNOWN);
  121.         ~CImpIMarshal(void);
  122.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  123.         STDMETHODIMP_(ULONG) AddRef(void);
  124.         STDMETHODIMP_(ULONG) Release(void);
  125.         STDMETHODIMP GetUnmarshalClass(REFIID, LPVOID, DWORD
  126.             , LPVOID, DWORD, LPCLSID);
  127.         STDMETHODIMP GetMarshalSizeMax(REFIID, LPVOID, DWORD
  128.             , LPVOID, DWORD, LPDWORD);
  129.         STDMETHODIMP MarshalInterface(LPSTREAM, REFIID, LPVOID
  130.             , DWORD, LPVOID, DWORD);
  131.         STDMETHODIMP UnmarshalInterface(LPSTREAM, REFIID, LPVOID *);
  132.         STDMETHODIMP ReleaseMarshalData(LPSTREAM);
  133.         STDMETHODIMP DisconnectObject(DWORD);
  134.     };
  135. #endif //_KOALA_H_