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.

204 lines
4.7 KiB

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