Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.6 KiB

  1. /****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : OutputStream.h
  4. Project Name : WMI Command Line
  5. Author Name : C V Nandi
  6. Date of Creation (dd/mm/yy) : 9th-July-2001
  7. Version Number : 1.0
  8. Brief Description : This file consist of class declaration of
  9. class CFileOutputStream and CStackUnknown
  10. Revision History :
  11. Last Modified By : C V Nandi
  12. Last Modified Date : 10th-July-2001
  13. ****************************************************************************/
  14. /*-------------------------------------------------------------------
  15. Class Name : CStackUnknown
  16. Class Type : Concrete
  17. Brief Description : Implementation of IUnknown for objects that are
  18. meant to be created on the stack. Because of this,
  19. all external references to this object must be
  20. released before this object is destructed.
  21. Super Classes : Base
  22. Sub Classes : CFileOutputStream
  23. Classes Used : None
  24. Interfaces Used : None
  25. --------------------------------------------------------------------*/
  26. template <class Base>
  27. class __declspec(novtable) CStackUnknown : public Base
  28. {
  29. public:
  30. //////////////////////////////////////////////////////////////////////////
  31. // IUnknown
  32. //
  33. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppv);
  34. virtual ULONG STDMETHODCALLTYPE AddRef() {return 1;}
  35. virtual ULONG STDMETHODCALLTYPE Release() {return 1;}
  36. };
  37. /*------------------------------------------------------------------------
  38. Name :QueryInterface
  39. Synopsis :This function overides the implemention of IUnknown
  40. interface.
  41. Type :Member Function
  42. Input parameter :
  43. riid - REFIID, reference ID.
  44. Output parameters :
  45. ppv - Pointer to object.
  46. Return Type :HRESULT
  47. Global Variables :None
  48. Calling Syntax :Called by interface
  49. Notes :None
  50. ------------------------------------------------------------------------*/
  51. template <class Base>
  52. HRESULT STDMETHODCALLTYPE
  53. CStackUnknown<Base>::QueryInterface(REFIID riid, void ** ppv)
  54. {
  55. if (riid == __uuidof(Base) || riid == __uuidof(IUnknown))
  56. {
  57. // No need to AddRef since this class will only be created on the stack
  58. *ppv = this;
  59. return S_OK;
  60. }
  61. *ppv = NULL;
  62. return E_NOINTERFACE;
  63. }
  64. /*-------------------------------------------------------------------
  65. Class Name : CFileOutputStream
  66. Class Type : Concrete
  67. Brief Description : Implements Write method of ISequentialStream on
  68. top of output stream HANDLE.
  69. Super Classes : CStackUnknown
  70. Sub Classes : None
  71. Classes Used : None
  72. Interfaces Used : None
  73. --------------------------------------------------------------------*/
  74. class CFileOutputStream : public CStackUnknown<ISequentialStream>
  75. {
  76. private:
  77. HANDLE m_hOutStream;
  78. bool m_bClose; // Close handle only if this class opened it
  79. public:
  80. CFileOutputStream() {m_bClose = FALSE;}
  81. ~CFileOutputStream() {Close();}
  82. HRESULT Init(HANDLE h);
  83. HRESULT Init(const _TCHAR * pwszFileName);
  84. void Close();
  85. //////////////////////////////////////////////////////////////////////////
  86. // ISequentialStream
  87. //
  88. virtual HRESULT STDMETHODCALLTYPE Read(void * pv,
  89. ULONG cb,
  90. ULONG * pcbRead){return E_NOTIMPL;}
  91. virtual HRESULT STDMETHODCALLTYPE Write(void const * pv,
  92. ULONG cb,
  93. ULONG * pcbWritten);
  94. };