Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / 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
- PersistenceTypeAttribute.cs
- DeadCharTextComposition.cs
- InvalidPrinterException.cs
- VisualBasicValue.cs
- FacetValues.cs
- ArraySegment.cs
- ProvidersHelper.cs
- SqlTypeSystemProvider.cs
- XmlIncludeAttribute.cs
- SqlMetaData.cs
- SBCSCodePageEncoding.cs
- Itemizer.cs
- ApplicationException.cs
- Invariant.cs
- COM2Properties.cs
- CommonGetThemePartSize.cs
- EnumerableRowCollection.cs
- HtmlElementEventArgs.cs
- TreeNodeBindingCollection.cs
- ToolStripHighContrastRenderer.cs
- ClientSettingsStore.cs
- VectorKeyFrameCollection.cs
- DataReaderContainer.cs
- NotSupportedException.cs
- HtmlInputControl.cs
- InvokeHandlers.cs
- BamlCollectionHolder.cs
- ClaimTypeElement.cs
- PageContentAsyncResult.cs
- SwitchAttribute.cs
- BuilderPropertyEntry.cs
- RawStylusInputCustomDataList.cs
- ProfilePropertySettingsCollection.cs
- ZipIOLocalFileBlock.cs
- RewritingProcessor.cs
- ResourcePool.cs
- ResourcePermissionBaseEntry.cs
- RegexWriter.cs
- ListenerElementsCollection.cs
- ADMembershipProvider.cs
- WSUtilitySpecificationVersion.cs
- GZipDecoder.cs
- LogSwitch.cs
- ProvidersHelper.cs
- EntityDescriptor.cs
- FragmentNavigationEventArgs.cs
- Timer.cs
- SqlProvider.cs
- odbcmetadatafactory.cs
- SessionIDManager.cs
- XmlQueryContext.cs
- SynchronizedChannelCollection.cs
- ViewPort3D.cs
- ParseHttpDate.cs
- HuffmanTree.cs
- OperationAbortedException.cs
- SHA1.cs
- NativeStructs.cs
- ViewBase.cs
- Authorization.cs
- EnvelopedPkcs7.cs
- WsdlBuildProvider.cs
- ScriptReferenceBase.cs
- CodeGenHelper.cs
- Wildcard.cs
- SelectionPattern.cs
- TargetConverter.cs
- securitycriticaldataClass.cs
- XamlToRtfWriter.cs
- XsltLoader.cs
- Font.cs
- RequestCacheEntry.cs
- SevenBitStream.cs
- ExceptionHelpers.cs
- SchemaTypeEmitter.cs
- externdll.cs
- StreamReader.cs
- LazyTextWriterCreator.cs
- Rotation3DKeyFrameCollection.cs
- Geometry.cs
- ObjectHandle.cs
- SafeSecurityHandles.cs
- GridEntryCollection.cs
- __Error.cs
- ZipFileInfoCollection.cs
- InternalBufferOverflowException.cs
- XPathAxisIterator.cs
- Control.cs
- Transform3DGroup.cs
- MailAddress.cs
- ScriptingScriptResourceHandlerSection.cs
- ViewManager.cs
- TextRangeSerialization.cs
- ParseChildrenAsPropertiesAttribute.cs
- Decoder.cs
- BreadCrumbTextConverter.cs
- WebPartZone.cs
- ReflectionPermission.cs
- CriticalExceptions.cs
- DigitalSignatureProvider.cs