Source code of Windows XP (NT5)
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.

138 lines
4.4 KiB

  1. #include "priv.h"
  2. #include "nullstm.h"
  3. #ifndef UNIX
  4. // A static empty stream implementation, for back compat & no memory hit
  5. //
  6. // Macros copied from cfdefs.h
  7. //
  8. #define STDMETHODX(fn) HRESULT STDMETHODCALLTYPE fn
  9. #define STDMETHODX_(ret,fn) ret STDMETHODCALLTYPE fn
  10. class CNullStream {
  11. public:
  12. IStream *vtable;
  13. STDMETHODX (QueryInterface)(REFIID riid, void **ppvObj);
  14. STDMETHODX_(ULONG, AddRef)();
  15. STDMETHODX_(ULONG, Release)();
  16. STDMETHODX (Read)(void *pv, ULONG cb, ULONG *pcbRead) { if (pcbRead) *pcbRead = 0; return E_NOTIMPL; }
  17. STDMETHODX (Write)(void const *pv, ULONG cb, ULONG *pcbWritten) { if (pcbWritten) *pcbWritten = 0; return E_NOTIMPL; }
  18. STDMETHODX (Seek)(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) { plibNewPosition->HighPart = plibNewPosition->LowPart = 0; return E_NOTIMPL; }
  19. STDMETHODX (SetSize)(ULARGE_INTEGER libNewSize) { return E_NOTIMPL; }
  20. STDMETHODX (CopyTo)(IStream *, ULARGE_INTEGER, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten) { if (pcbRead) pcbRead->LowPart = pcbRead->HighPart = 0; if (pcbWritten) pcbWritten->LowPart = pcbWritten->HighPart = 0; return E_NOTIMPL; }
  21. STDMETHODX (Commit)(DWORD) { return E_NOTIMPL; }
  22. STDMETHODX (Revert)() { return E_NOTIMPL; }
  23. STDMETHODX (LockRegion)(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL; }
  24. STDMETHODX (UnlockRegion)(ULARGE_INTEGER, ULARGE_INTEGER, DWORD) { return E_NOTIMPL; }
  25. STDMETHODX (Stat)(STATSTG *, DWORD) { return E_NOTIMPL; }
  26. STDMETHODX (Clone)(IStream **ppstm) { *ppstm = NULL; return E_NOTIMPL; }
  27. };
  28. STDMETHODIMP CNullStream::QueryInterface(REFIID riid, void **ppvObj)
  29. {
  30. if (IsEqualIID(riid, IID_IStream) || IsEqualIID(riid, IID_IUnknown))
  31. {
  32. *ppvObj=this;
  33. // DllAddRef(); // if this dll supported CoCreateInstance
  34. return S_OK;
  35. }
  36. *ppvObj = NULL;
  37. return E_NOINTERFACE;
  38. }
  39. STDMETHODIMP_(ULONG) CNullStream::AddRef()
  40. {
  41. // DllAddRef(); // if this dll supported CoCreateInstance
  42. return 2;
  43. }
  44. STDMETHODIMP_(ULONG) CNullStream::Release()
  45. {
  46. // DllRelease(); // if this dll supported CoCreateInstance
  47. return 1;
  48. }
  49. // We need the C vtable declaration, but this is .CPP.
  50. // Simulate the vtable, swiped from objidl.h and touched up.
  51. //
  52. typedef struct IStreamVtbl
  53. {
  54. HRESULT ( STDMETHODCALLTYPE CNullStream::*QueryInterface )(REFIID riid, void **ppvObject);
  55. ULONG ( STDMETHODCALLTYPE CNullStream::*AddRef )( );
  56. ULONG ( STDMETHODCALLTYPE CNullStream::*Release )( );
  57. HRESULT ( STDMETHODCALLTYPE CNullStream::*Read )(
  58. void *pv,
  59. ULONG cb,
  60. ULONG *pcbRead);
  61. HRESULT ( STDMETHODCALLTYPE CNullStream::*Write )(
  62. const void *pv,
  63. ULONG cb,
  64. ULONG *pcbWritten);
  65. HRESULT ( STDMETHODCALLTYPE CNullStream::*Seek )(
  66. LARGE_INTEGER dlibMove,
  67. DWORD dwOrigin,
  68. ULARGE_INTEGER *plibNewPosition);
  69. HRESULT ( STDMETHODCALLTYPE CNullStream::*SetSize )(
  70. ULARGE_INTEGER libNewSize);
  71. HRESULT ( STDMETHODCALLTYPE CNullStream::*CopyTo )(
  72. IStream *pstm,
  73. ULARGE_INTEGER cb,
  74. ULARGE_INTEGER *pcbRead,
  75. ULARGE_INTEGER *pcbWritten);
  76. HRESULT ( STDMETHODCALLTYPE CNullStream::*Commit )(
  77. DWORD grfCommitFlags);
  78. HRESULT ( STDMETHODCALLTYPE CNullStream::*Revert )( );
  79. HRESULT ( STDMETHODCALLTYPE CNullStream::*LockRegion )(
  80. ULARGE_INTEGER libOffset,
  81. ULARGE_INTEGER cb,
  82. DWORD dwLockType);
  83. HRESULT ( STDMETHODCALLTYPE CNullStream::*UnlockRegion )(
  84. ULARGE_INTEGER libOffset,
  85. ULARGE_INTEGER cb,
  86. DWORD dwLockType);
  87. HRESULT ( STDMETHODCALLTYPE CNullStream::*Stat )(
  88. STATSTG *pstatstg,
  89. DWORD grfStatFlag);
  90. HRESULT ( STDMETHODCALLTYPE CNullStream::*Clone )(
  91. IStream **ppstm);
  92. } IStreamVtbl;
  93. IStream* SHConstNullStream()
  94. {
  95. static const IStreamVtbl c_NullStream = {
  96. CNullStream::QueryInterface,
  97. CNullStream::AddRef,
  98. CNullStream::Release,
  99. CNullStream::Read,
  100. CNullStream::Write,
  101. CNullStream::Seek,
  102. CNullStream::SetSize,
  103. CNullStream::CopyTo,
  104. CNullStream::Commit,
  105. CNullStream::Revert,
  106. CNullStream::LockRegion,
  107. CNullStream::UnlockRegion,
  108. CNullStream::Stat,
  109. CNullStream::Clone,
  110. };
  111. static const void * vtable = (void*)&c_NullStream;
  112. return (IStream*)&vtable;
  113. }
  114. #endif