本文整理汇总了C#中IStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# IStream.Seek方法的具体用法?C# IStream.Seek怎么用?C# IStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStream
的用法示例。
在下文中一共展示了IStream.Seek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAllBytes
private unsafe static void ReadAllBytes(IStream stream, out byte[] bytes, out int size)
{
const int STREAM_SEEK_SET = 0;
size = GetStreamSize(stream);
stream.Seek(0, STREAM_SEEK_SET, IntPtr.Zero);
bytes = new byte[size];
int bytesRead = 0;
stream.Read(bytes, size, (IntPtr)(&bytesRead));
if (bytesRead != size)
{
// TODO:
throw new NotSupportedException();
}
}
示例2: UnmanagedStream
public UnmanagedStream(IStream stream, bool leaveOpen = false)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
// Mask with only Read/Write/ReadWrite.
var accessMode = GetAccessMode(stream) & (NativeMethods.Stgm.Read | NativeMethods.Stgm.Write | NativeMethods.Stgm.ReadWrite);
CanRead = accessMode == NativeMethods.Stgm.Read || accessMode == NativeMethods.Stgm.ReadWrite;
CanWrite = accessMode == NativeMethods.Stgm.Write || accessMode == NativeMethods.Stgm.ReadWrite;
// Check if the stream is seekable.
try
{
stream.Seek(0, (int)SeekOrigin.Current, IntPtr.Zero);
CanSeek = true;
}
catch (COMException ex) when ((NativeMethods.STG_E)ex.HResult == NativeMethods.STG_E.SeekError)
{
// Ignore
}
// Set up two pointers used by the class for retrieving info from the underlying IStream.
_hBytesRead = Marshal.AllocCoTaskMem(4); // Pointer to an Int32.
try
{
_hPosition = Marshal.AllocCoTaskMem(8); // Pointer to an Int64.
}
catch (OutOfMemoryException)
{
// If this has failed, we need to clean up the previous memory initialization call, as the object will be invalid.
Marshal.FreeCoTaskMem(_hBytesRead);
_hBytesRead = IntPtr.Zero;
throw; // And now, rethrow.
}
_stream = stream;
_leaveOpen = leaveOpen;
}
示例3: ToMemoryStream
private unsafe MemoryStream ToMemoryStream(IStream comStream)
{
MemoryStream stream = new MemoryStream();
byte[] pv = new byte[100];
uint num = 0;
IntPtr pcbRead = new IntPtr((void*) &num);
comStream.Seek((long) 0, 0, IntPtr.Zero);
do
{
num = 0;
comStream.Read(pv, pv.Length, pcbRead);
stream.Write(pv, 0, (int) num);
} while (num > 0);
return stream;
}
示例4: PptStreamContainsEncryptedLabel
static bool PptStreamContainsEncryptedLabel(IStream pptStream)
{
var ptrReadBytes = Marshal.AllocHGlobal(sizeof(ulong));
try
{
int CHUNK_SIZE = 512;
var lastChunk = new byte[CHUNK_SIZE];
System.Runtime.InteropServices.ComTypes.STATSTG stat;
pptStream.Stat(out stat, STATFLAG_DEFAULT);
if (stat.cbSize > CHUNK_SIZE)
{
pptStream.Seek(stat.cbSize - CHUNK_SIZE, STREAM_SEEK_START, IntPtr.Zero);
}
pptStream.Read(lastChunk, CHUNK_SIZE, ptrReadBytes);
var contentAsText = Encoding.ASCII.GetString(lastChunk);
return contentAsText.Contains(ENCODED_LABEL_AS_TEXT);
}
finally
{
Marshal.FreeHGlobal(ptrReadBytes);
}
}
示例5: GetBufferFromIStream
private static byte[] GetBufferFromIStream(IStream comStream)
{
LARGE_INTEGER zeroPos;
zeroPos.QuadPart = 0;
ULARGE_INTEGER[] streamPosition = new ULARGE_INTEGER[1];
comStream.Seek(zeroPos, (uint)STREAM_SEEK.STREAM_SEEK_CUR, streamPosition);
comStream.Seek(zeroPos, (uint)STREAM_SEEK.STREAM_SEEK_SET, null);
Microsoft.VisualStudio.OLE.Interop.STATSTG[] stat = new Microsoft.VisualStudio.OLE.Interop.STATSTG[1];
comStream.Stat(stat, (uint)STATFLAG.STATFLAG_NONAME);
int bufferLength = (int)stat[0].cbSize.QuadPart;
byte[] buffer = new byte[bufferLength];
uint bytesRead = 0;
comStream.Read(buffer, (uint)buffer.Length, out bytesRead);
// return the stream to its previous location
LARGE_INTEGER newPos;
newPos.QuadPart = (long)streamPosition[0].QuadPart;
comStream.Seek(newPos, (uint)STREAM_SEEK.STREAM_SEEK_SET, null);
return buffer;
}