Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Internal / SapiInterop / SpStreamWrapper.cs / 1 / SpStreamWrapper.cs
//------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // // // // Description: // Maps an audio stream the SAPI ISpStreamFormat // // History: // 7/10/2005 jeanfp //----------------------------------------------------------------- using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Speech.AudioFormat; using System.Speech.Internal.SapiInterop; using System.Speech.Internal.Synthesis; #pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages. using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG; namespace System.Speech.Internal.SapiInterop { internal class SpStreamWrapper : IStream, IDisposable { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal SpStreamWrapper (Stream stream) { _stream = stream; _endOfStreamPosition = stream.Length; } ////// /// public void Dispose () { _stream.Dispose (); GC.SuppressFinalize (this); } #endregion //******************************************************************** // // Public Methods // //******************************************************************* #region public Methods #region ISpStreamFormat interface implementation public void Read (byte [] pv, int cb, IntPtr pcbRead) { if (_endOfStreamPosition >= 0 && _stream.Position + cb > _endOfStreamPosition) { cb = (int) (_endOfStreamPosition - _stream.Position); } int read = 0; try { read = _stream.Read (pv, 0, cb); } catch (EndOfStreamException) { read = 0; } if (pcbRead != IntPtr.Zero) { Marshal.WriteIntPtr (pcbRead, new IntPtr (read)); } } public void Write (byte [] pv, int cb, IntPtr pcbWritten) { throw new NotSupportedException (); } public void Seek (long offset, int seekOrigin, IntPtr plibNewPosition) { _stream.Seek (offset, (SeekOrigin) seekOrigin); if (plibNewPosition != IntPtr.Zero) { Marshal.WriteIntPtr (plibNewPosition, new IntPtr (_stream.Position)); } } public void SetSize (long libNewSize) { throw new NotSupportedException (); } public void CopyTo (IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten) { throw new NotSupportedException (); } public void Commit (int grfCommitFlags) { _stream.Flush (); } public void Revert () { throw new NotSupportedException (); } public void LockRegion (long libOffset, long cb, int dwLockType) { throw new NotSupportedException (); } public void UnlockRegion (long libOffset, long cb, int dwLockType) { throw new NotSupportedException (); } public void Stat (out STATSTG pstatstg, int grfStatFlag) { pstatstg = new STATSTG (); pstatstg.cbSize = _stream.Length; } public void Clone (out IStream ppstm) { throw new NotSupportedException (); } #endregion #endregion //******************************************************************** // // Private Fields // //******************************************************************** #region Private Fields private Stream _stream; protected long _endOfStreamPosition = -1; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // // // // Description: // Maps an audio stream the SAPI ISpStreamFormat // // History: // 7/10/2005 jeanfp //----------------------------------------------------------------- using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Speech.AudioFormat; using System.Speech.Internal.SapiInterop; using System.Speech.Internal.Synthesis; #pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages. using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG; namespace System.Speech.Internal.SapiInterop { internal class SpStreamWrapper : IStream, IDisposable { //******************************************************************* // // Constructors // //******************************************************************* #region Constructors internal SpStreamWrapper (Stream stream) { _stream = stream; _endOfStreamPosition = stream.Length; } ////// /// public void Dispose () { _stream.Dispose (); GC.SuppressFinalize (this); } #endregion //******************************************************************** // // Public Methods // //******************************************************************* #region public Methods #region ISpStreamFormat interface implementation public void Read (byte [] pv, int cb, IntPtr pcbRead) { if (_endOfStreamPosition >= 0 && _stream.Position + cb > _endOfStreamPosition) { cb = (int) (_endOfStreamPosition - _stream.Position); } int read = 0; try { read = _stream.Read (pv, 0, cb); } catch (EndOfStreamException) { read = 0; } if (pcbRead != IntPtr.Zero) { Marshal.WriteIntPtr (pcbRead, new IntPtr (read)); } } public void Write (byte [] pv, int cb, IntPtr pcbWritten) { throw new NotSupportedException (); } public void Seek (long offset, int seekOrigin, IntPtr plibNewPosition) { _stream.Seek (offset, (SeekOrigin) seekOrigin); if (plibNewPosition != IntPtr.Zero) { Marshal.WriteIntPtr (plibNewPosition, new IntPtr (_stream.Position)); } } public void SetSize (long libNewSize) { throw new NotSupportedException (); } public void CopyTo (IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten) { throw new NotSupportedException (); } public void Commit (int grfCommitFlags) { _stream.Flush (); } public void Revert () { throw new NotSupportedException (); } public void LockRegion (long libOffset, long cb, int dwLockType) { throw new NotSupportedException (); } public void UnlockRegion (long libOffset, long cb, int dwLockType) { throw new NotSupportedException (); } public void Stat (out STATSTG pstatstg, int grfStatFlag) { pstatstg = new STATSTG (); pstatstg.cbSize = _stream.Length; } public void Clone (out IStream ppstm) { throw new NotSupportedException (); } #endregion #endregion //******************************************************************** // // Private Fields // //******************************************************************** #region Private Fields private Stream _stream; protected long _endOfStreamPosition = -1; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AxisAngleRotation3D.cs
- DispatcherExceptionEventArgs.cs
- DigitShape.cs
- TextEditor.cs
- CodeGroup.cs
- PropertyPath.cs
- DataTablePropertyDescriptor.cs
- ListViewContainer.cs
- HtmlDocument.cs
- dbenumerator.cs
- WorkflowDesignerColors.cs
- KeyManager.cs
- ThumbAutomationPeer.cs
- NotImplementedException.cs
- WindowsSpinner.cs
- XmlEntity.cs
- XmlObjectSerializer.cs
- HostVisual.cs
- DesignerTextViewAdapter.cs
- VolatileEnlistmentMultiplexing.cs
- FactoryRecord.cs
- StackBuilderSink.cs
- BinaryOperationBinder.cs
- EntityCodeGenerator.cs
- BounceEase.cs
- GridViewRowPresenterBase.cs
- HostedElements.cs
- LinearKeyFrames.cs
- IListConverters.cs
- SourceFileBuildProvider.cs
- ObjectItemLoadingSessionData.cs
- BinaryFormatterWriter.cs
- HttpsChannelFactory.cs
- AnnotationResource.cs
- ReferencedCollectionType.cs
- CaseStatementSlot.cs
- GridViewRowEventArgs.cs
- PartialCachingControl.cs
- FormClosedEvent.cs
- HttpListenerElement.cs
- MtomMessageEncodingBindingElement.cs
- OverrideMode.cs
- NonVisualControlAttribute.cs
- InkCanvasAutomationPeer.cs
- PathFigure.cs
- FileFormatException.cs
- HandleTable.cs
- WebBrowserSiteBase.cs
- BitSet.cs
- RegexTree.cs
- WindowsTooltip.cs
- GroupBoxRenderer.cs
- SafeEventLogWriteHandle.cs
- DataGridCell.cs
- Switch.cs
- MDIWindowDialog.cs
- PropertyEntry.cs
- ComponentEditorPage.cs
- WsrmTraceRecord.cs
- CultureTable.cs
- XPathDocumentNavigator.cs
- JapaneseLunisolarCalendar.cs
- ReadOnlyDataSource.cs
- Utils.cs
- ContentValidator.cs
- LayoutEditorPart.cs
- Events.cs
- AtomPub10CategoriesDocumentFormatter.cs
- WaitForChangedResult.cs
- WebPartMenuStyle.cs
- StyleConverter.cs
- XsdDataContractExporter.cs
- Triangle.cs
- TextLineBreak.cs
- MSHTMLHostUtil.cs
- WaitHandleCannotBeOpenedException.cs
- CodeCommentStatementCollection.cs
- altserialization.cs
- WebBrowserContainer.cs
- ObjectItemAttributeAssemblyLoader.cs
- DataGridViewHitTestInfo.cs
- BadImageFormatException.cs
- WebBrowsableAttribute.cs
- DataGridViewRowCancelEventArgs.cs
- KeyTimeConverter.cs
- InplaceBitmapMetadataWriter.cs
- WsdlContractConversionContext.cs
- DataView.cs
- EventLogPermission.cs
- NavigationWindowAutomationPeer.cs
- RuleSettingsCollection.cs
- TriState.cs
- ConfigurationManagerHelper.cs
- AudioBase.cs
- DataGridTablesFactory.cs
- DataReaderContainer.cs
- Int32Storage.cs
- SerializableTypeCodeDomSerializer.cs
- BufferedReadStream.cs
- AliasGenerator.cs