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.

143 lines
3.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ByteBuffer.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // ByteBuffer.h : Declaration of the CByteBuffer
  11. #ifndef __BYTEBUFFER_H_
  12. #define __BYTEBUFFER_H_
  13. #include "resource.h" // main symbols
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CByteBuffer
  16. class ATL_NO_VTABLE CByteBuffer :
  17. public CComObjectRootEx<CComMultiThreadModel>,
  18. public CComCoClass<CByteBuffer, &CLSID_CByteBuffer>,
  19. public IDispatchImpl<IByteBuffer, &IID_IByteBuffer, &LIBID_SCARDSSPLib>
  20. {
  21. public:
  22. CByteBuffer()
  23. {
  24. m_pUnkMarshaler = NULL;
  25. m_pStreamBuf = NULL;
  26. }
  27. DECLARE_REGISTRY_RESOURCEID(IDR_BYTEBUFFER)
  28. DECLARE_GET_CONTROLLING_UNKNOWN()
  29. DECLARE_PROTECT_FINAL_CONSTRUCT()
  30. BEGIN_COM_MAP(CByteBuffer)
  31. COM_INTERFACE_ENTRY(IByteBuffer)
  32. COM_INTERFACE_ENTRY(IDispatch)
  33. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  34. END_COM_MAP()
  35. HRESULT FinalConstruct()
  36. {
  37. return CoCreateFreeThreadedMarshaler(
  38. GetControllingUnknown(), &m_pUnkMarshaler.p);
  39. }
  40. void FinalRelease()
  41. {
  42. m_pUnkMarshaler.Release();
  43. if (NULL != m_pStreamBuf)
  44. m_pStreamBuf->Release();
  45. }
  46. LPSTREAM Stream(void)
  47. {
  48. if (NULL == m_pStreamBuf)
  49. {
  50. HRESULT hr;
  51. hr = CreateStreamOnHGlobal(NULL, TRUE, &m_pStreamBuf);
  52. if (FAILED(hr))
  53. throw hr;
  54. }
  55. return m_pStreamBuf;
  56. }
  57. CComPtr<IUnknown> m_pUnkMarshaler;
  58. // IByteBuffer
  59. public:
  60. STDMETHOD(get_Stream)(
  61. /* [retval][out] */ LPSTREAM __RPC_FAR *ppStream);
  62. STDMETHOD(put_Stream)(
  63. /* [in] */ LPSTREAM pStream);
  64. STDMETHOD(Clone)(
  65. /* [out][in] */ LPBYTEBUFFER __RPC_FAR *ppByteBuffer);
  66. STDMETHOD(Commit)(
  67. /* [in] */ LONG grfCommitFlags);
  68. STDMETHOD(CopyTo)(
  69. /* [out][in] */ LPBYTEBUFFER __RPC_FAR *ppByteBuffer,
  70. /* [in] */ LONG cb,
  71. /* [defaultvalue][out][in] */ LONG __RPC_FAR *pcbRead = 0,
  72. /* [defaultvalue][out][in] */ LONG __RPC_FAR *pcbWritten = 0);
  73. STDMETHOD(Initialize)(
  74. /* [defaultvalue][in] */ LONG lSize = 1,
  75. /* [defaultvalue][in] */ BYTE __RPC_FAR *pData = 0);
  76. STDMETHOD(LockRegion)(
  77. /* [in] */ LONG libOffset,
  78. /* [in] */ LONG cb,
  79. /* [in] */ LONG dwLockType);
  80. STDMETHOD(Read)(
  81. /* [out][in] */ BYTE __RPC_FAR *pByte,
  82. /* [in] */ LONG cb,
  83. /* [defaultvalue][out][in] */ LONG __RPC_FAR *pcbRead = 0);
  84. STDMETHOD(Revert)(void);
  85. STDMETHOD(Seek)(
  86. /* [in] */ LONG dLibMove,
  87. /* [in] */ LONG dwOrigin,
  88. /* [defaultvalue][out][in] */ LONG __RPC_FAR *pLibnewPosition = 0);
  89. STDMETHOD(SetSize)(
  90. /* [in] */ LONG libNewSize);
  91. STDMETHOD(Stat)(
  92. /* [out][in] */ LPSTATSTRUCT pstatstg,
  93. /* [in] */ LONG grfStatFlag);
  94. STDMETHOD(UnlockRegion)(
  95. /* [in] */ LONG libOffset,
  96. /* [in] */ LONG cb,
  97. /* [in] */ LONG dwLockType);
  98. STDMETHOD(Write)(
  99. /* [out][in] */ BYTE __RPC_FAR *pByte,
  100. /* [in] */ LONG cb,
  101. /* [out][in] */ LONG __RPC_FAR *pcbWritten);
  102. protected:
  103. LPSTREAM m_pStreamBuf;
  104. };
  105. inline CByteBuffer *
  106. NewByteBuffer(
  107. void)
  108. {
  109. return (CByteBuffer *)NewObject(CLSID_CByteBuffer, IID_IByteBuffer);
  110. }
  111. #endif //__BYTEBUFFER_H_