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.

200 lines
4.3 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. //
  3. // riff.h
  4. //
  5. #include <objbase.h>
  6. #ifndef __RIFF__
  7. #define __RIFF__
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #define FixBytes(a1,a2)
  11. // {0D5057E1-8889-11CF-B9DA-00AA00C08146}
  12. DEFINE_GUID( IID_IRIFFStream, 0xd5057e1, 0x8889, 0x11cf, 0xb9, 0xda, 0x0, 0xaa, 0x0, 0xc0, 0x81, 0x46 );
  13. #undef INTERFACE
  14. #define INTERFACE IRIFFStream
  15. DECLARE_INTERFACE_(IRIFFStream, IUnknown)
  16. {
  17. // IUnknown members
  18. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID *ppv) PURE;
  19. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  20. STDMETHOD_(ULONG, Release)(THIS) PURE;
  21. // IMKRIFFStream members
  22. STDMETHOD(Descend)(LPMMCKINFO lpck, LPMMCKINFO lpckParent, UINT wFlags) PURE;
  23. STDMETHOD(Ascend)(LPMMCKINFO lpck, UINT wFlags) PURE;
  24. STDMETHOD(CreateChunk)(LPMMCKINFO lpck, UINT wFlags) PURE;
  25. STDMETHOD(SetStream)(LPSTREAM pStream) PURE;
  26. STDMETHOD_(LPSTREAM, GetStream)() PURE;
  27. };
  28. struct CRIFFStream : IRIFFStream
  29. {
  30. ///// object state
  31. ULONG m_cRef; // object reference count
  32. IStream* m_pStream; // stream to operate on
  33. ///// construction and destruction
  34. CRIFFStream(IStream* pStream)
  35. {
  36. m_cRef = 1;
  37. // replaced a call to SetStream with the following to avoid releasing an
  38. // unallocated stream
  39. m_pStream = pStream;
  40. if( m_pStream != NULL )
  41. {
  42. m_pStream->AddRef();
  43. }
  44. }
  45. ~CRIFFStream()
  46. {
  47. if( m_pStream != NULL )
  48. {
  49. m_pStream->Release();
  50. }
  51. }
  52. ///// IUnknown methods
  53. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj)
  54. {
  55. if( IsEqualIID( riid, IID_IUnknown ) ||
  56. IsEqualIID( riid, IID_IRIFFStream ) )
  57. {
  58. *ppvObj = (IRIFFStream*)this;
  59. AddRef();
  60. return NOERROR;
  61. }
  62. *ppvObj = NULL;
  63. return E_NOINTERFACE;
  64. }
  65. STDMETHODIMP_(ULONG) AddRef()
  66. {
  67. return ++m_cRef;
  68. }
  69. STDMETHODIMP_(ULONG) Release()
  70. {
  71. if( --m_cRef == 0L )
  72. {
  73. delete this;
  74. return 0;
  75. }
  76. return m_cRef;
  77. }
  78. // IAARIFFStream methods
  79. STDMETHODIMP Descend(LPMMCKINFO lpck, LPMMCKINFO lpckParent, UINT wFlags);
  80. STDMETHODIMP Ascend(LPMMCKINFO lpck, UINT /*wFlags*/);
  81. STDMETHODIMP CreateChunk(LPMMCKINFO lpck, UINT wFlags);
  82. STDMETHOD(SetStream)(LPSTREAM pStream)
  83. {
  84. if( m_pStream != NULL )
  85. {
  86. m_pStream->Release();
  87. }
  88. m_pStream = pStream;
  89. if( m_pStream != NULL )
  90. {
  91. m_pStream->AddRef();
  92. }
  93. return S_OK;
  94. }
  95. STDMETHOD_(LPSTREAM, GetStream)()
  96. {
  97. if( m_pStream != NULL )
  98. {
  99. m_pStream->AddRef();
  100. }
  101. return m_pStream;
  102. }
  103. };
  104. /*
  105. // seeks to a 32-bit position in a stream.
  106. HRESULT __inline StreamSeek( LPSTREAM pStream, long lSeekTo, DWORD dwOrigin )
  107. {
  108. LARGE_INTEGER li;
  109. if( lSeekTo < 0 )
  110. {
  111. li.HighPart = -1;
  112. }
  113. else
  114. {
  115. li.HighPart = 0;
  116. }
  117. li.LowPart = lSeekTo;
  118. return pStream->Seek( li, dwOrigin, NULL );
  119. }
  120. // returns the current 32-bit position in a stream.
  121. DWORD __inline StreamTell( LPSTREAM pStream )
  122. {
  123. LARGE_INTEGER li;
  124. ULARGE_INTEGER ul;
  125. #ifdef DBG
  126. HRESULT hr;
  127. #endif
  128. li.HighPart = 0;
  129. li.LowPart = 0;
  130. #ifdef DBG
  131. hr = pStream->Seek( li, STREAM_SEEK_CUR, &ul );
  132. if( FAILED( hr ) )
  133. #else
  134. if( FAILED( pStream->Seek( li, STREAM_SEEK_CUR, &ul ) ) )
  135. #endif
  136. {
  137. return 0;
  138. }
  139. return ul.LowPart;
  140. }
  141. // this function gets a long that is formatted the correct way
  142. // i.e. the motorola way as opposed to the intel way
  143. BOOL __inline GetMLong( LPSTREAM pStream, DWORD& dw )
  144. {
  145. union uLong
  146. {
  147. unsigned char buf[4];
  148. DWORD dw;
  149. } u;
  150. unsigned char ch;
  151. if( FAILED( pStream->Read( u.buf, 4, NULL ) ) )
  152. {
  153. return FALSE;
  154. }
  155. #ifndef _MAC
  156. // swap bytes
  157. ch = u.buf[0];
  158. u.buf[0] = u.buf[3];
  159. u.buf[3] = ch;
  160. ch = u.buf[1];
  161. u.buf[1] = u.buf[2];
  162. u.buf[2] = ch;
  163. #endif
  164. dw = u.dw;
  165. return TRUE;
  166. }
  167. BOOL __inline IsGUIDZero( REFGUID guid )
  168. {
  169. GUID g;
  170. memset( &g, 0, sizeof( g ) );
  171. return IsEqualGUID( g, guid );
  172. }
  173. // misc function prototypes
  174. STDAPI AllocFileStream( LPCSTR szFileName, DWORD dwDesiredAccess, IStream **ppstream );
  175. */
  176. STDAPI AllocRIFFStream( IStream* pStream, IRIFFStream** ppRiff );
  177. #endif // __RIFF_H__