public void Seek(long dlibMove, STREAM_SEEK dwOrigin, IntPtr plibNewPosition) { SeekOrigin seekOrigin; switch (dwOrigin) { case STREAM_SEEK.STREAM_SEEK_SET: seekOrigin = SeekOrigin.Begin; break; case STREAM_SEEK.STREAM_SEEK_CUR: seekOrigin = SeekOrigin.Current; break; case STREAM_SEEK.STREAM_SEEK_END: seekOrigin = SeekOrigin.End; break; default: throw new ArgumentOutOfRangeException(nameof(dwOrigin)); } long newPosition = UnderlyingStream.Seek(dlibMove, seekOrigin); if (plibNewPosition != IntPtr.Zero) { Marshal.WriteInt64(plibNewPosition, 0, newPosition); } }
/// <summary> /// Changes the seek pointer to a new location relative to the beginning of the /// stream, to the end of the stream, or to the current seek pointer. /// </summary> /// <param name="dlibMove">The displacement to add to to dwOrigin</param> /// <param name="dwOrigin"> /// The origin of the seek. The origin can be the beginning of the file, the /// current seek pointer, or the end of the file. /// </param> /// <param name="plibNewPosition"> /// Upon return, contains the offset of the seek pointer from the beginning of the stream. /// </param> public void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition) { Marshal.WriteInt64(plibNewPosition, stream.Position); long num = 0L; switch (dwOrigin) { case 0: // STREAM_SEEK_SET num = dlibMove; break; case 1: // STREAM_SEEK_CUR num = stream.Position + dlibMove; break; case 2: // STREAM_SEEK_END num = stream.Length + dlibMove; break; default: return; } if ((num >= 0L) && (num < stream.Length)) { stream.Position = num; Marshal.WriteInt64(plibNewPosition, stream.Position); } }
void IStream.Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition) { if (plibNewPosition != IntPtr.Zero) { Marshal.WriteInt64(plibNewPosition, 0); } }
void IStream.Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition) { var origin = (SeekOrigin)dwOrigin; var pos = Seek(dlibMove, origin); if (plibNewPosition != IntPtr.Zero) { Marshal.WriteInt64(plibNewPosition, pos); } }
/// <summary> /// Writes a specified number of bytes into the stream object starting at the /// current seek pointer. /// </summary> /// <param name="pv">The buffer to write this stream to.</param> /// <param name="cb">The number of bytes to write to the stream.</param> /// <param name="pcbWritten"> /// Upon return, contains the actual number of bytes written to the stream object. /// If the caller sets this pointer to System.IntPtr.Zero, this method does not provide /// the actual number of bytes written. /// </param> public void Write(byte[] pv, int cb, IntPtr pcbWritten) { Marshal.WriteInt64(pcbWritten, 0L); stream.Write(pv, 0, cb); Marshal.WriteInt64(pcbWritten, (long)cb); }
/// <summary> /// Reads a specified number of bytes from the stream object into memory starting /// at the current seek pointer. /// </summary> /// <param name="pv">Upon return, contains the data read from the stream.</param> /// <param name="cb">The number of bytes to read from the stream object.</param> /// <param name="pcbRead"> /// A pointer to a ULONG variable that receives the actual number of bytes read /// from the stream object. /// </param> public void Read(byte[] pv, int cb, IntPtr pcbRead) { Marshal.WriteInt64(pcbRead, (long)stream.Read(pv, 0, cb)); }