internal static void StaticDispose(ref StreamDescriptor pSD) { Debug.Assert(((IntPtr)pSD.m_handle) != IntPtr.Zero, "If this asserts fires: why is it firing. It might be legal in future."); StreamAsIStream sais = (StreamAsIStream)(pSD.m_handle.Target); ((System.Runtime.InteropServices.GCHandle)(pSD.m_handle)).Free(); }
internal static IntPtr IStreamFrom(System.IO.Stream stream) { if (stream == null) { throw new System.ArgumentNullException("stream"); } IntPtr pStream = IntPtr.Zero; StreamAsIStream sais = new StreamAsIStream(stream); StreamDescriptor sd = new StreamDescriptor(); sd.pfnDispose = StaticPtrs.pfnDispose; sd.pfnClone = StaticPtrs.pfnClone; sd.pfnCommit = StaticPtrs.pfnCommit; sd.pfnCopyTo = StaticPtrs.pfnCopyTo; sd.pfnLockRegion = StaticPtrs.pfnLockRegion; sd.pfnRead = StaticPtrs.pfnRead; sd.pfnRevert = StaticPtrs.pfnRevert; unsafe { sd.pfnSeek = StaticPtrs.pfnSeek; } sd.pfnSetSize = StaticPtrs.pfnSetSize; sd.pfnStat = StaticPtrs.pfnStat; sd.pfnUnlockRegion = StaticPtrs.pfnUnlockRegion; sd.pfnWrite = StaticPtrs.pfnWrite; sd.pfnCanWrite = StaticPtrs.pfnCanWrite; sd.pfnCanSeek = StaticPtrs.pfnCanSeek; sd.m_handle = System.Runtime.InteropServices.GCHandle.Alloc(sais, System.Runtime.InteropServices.GCHandleType.Normal); HRESULT.Check(UnsafeNativeMethods.MilCoreApi.MILCreateStreamFromStreamDescriptor(ref sd, out pStream)); return(pStream); }
internal static int Clone(ref StreamDescriptor pSD, out IntPtr stream) { return (StreamAsIStream.FromSD(ref pSD)).Clone(out stream); }
internal static int Write(ref StreamDescriptor pSD, byte[] buffer, uint cb, out uint cbWritten) { return((StreamAsIStream.FromSD(ref pSD)).Write(buffer, cb, out cbWritten)); }
internal static int Stat(ref StreamDescriptor pSD, out System.Runtime.InteropServices.ComTypes.STATSTG statstg, uint grfStatFlag) { return((StreamAsIStream.FromSD(ref pSD)).Stat(out statstg, grfStatFlag)); }
internal unsafe static int Seek(ref StreamDescriptor pSD, long offset, uint origin, long *plibNewPostion) { return((StreamAsIStream.FromSD(ref pSD)).Seek(offset, origin, plibNewPostion)); }
internal static int Read(ref StreamDescriptor pSD, byte[] buffer, uint cb, out uint cbRead) { return((StreamAsIStream.FromSD(ref pSD)).Read(buffer, cb, out cbRead)); }
internal static int Commit(ref StreamDescriptor pSD, UInt32 grfCommitFlags) { return((StreamAsIStream.FromSD(ref pSD)).Commit(grfCommitFlags)); }
internal static int SetSize(ref StreamDescriptor pSD, long value) { return (StreamAsIStream.FromSD(ref pSD)).SetSize(value); }
internal unsafe static int Seek(ref StreamDescriptor pSD, long offset, uint origin, long* plibNewPostion) { return (StreamAsIStream.FromSD(ref pSD)).Seek(offset, origin, plibNewPostion); }
internal static int Revert(ref StreamDescriptor pSD) { return (StreamAsIStream.FromSD(ref pSD)).Revert(); }
internal static int Read(ref StreamDescriptor pSD, byte[] buffer, uint cb, out uint cbRead) { return (StreamAsIStream.FromSD(ref pSD)).Read(buffer, cb, out cbRead); }
internal static int CopyTo(ref StreamDescriptor pSD, IntPtr pstm, long cb, out long cbRead, out long cbWritten) { return (StreamAsIStream.FromSD(ref pSD)).CopyTo(pstm, cb, out cbRead, out cbWritten); }
internal static int Commit(ref StreamDescriptor pSD, UInt32 grfCommitFlags) { return (StreamAsIStream.FromSD(ref pSD)).Commit(grfCommitFlags); }
internal static StreamAsIStream FromSD(ref StreamDescriptor sd) { Debug.Assert(((IntPtr)sd.m_handle) != IntPtr.Zero, "Stream is disposed."); System.Runtime.InteropServices.GCHandle handle = (System.Runtime.InteropServices.GCHandle)(sd.m_handle); return((StreamAsIStream)(handle.Target)); }
internal static int Clone(ref StreamDescriptor pSD, out IntPtr stream) { return((StreamAsIStream.FromSD(ref pSD)).Clone(out stream)); }
internal static int Stat(ref StreamDescriptor pSD, out System.Runtime.InteropServices.ComTypes.STATSTG statstg, uint grfStatFlag) { return (StreamAsIStream.FromSD(ref pSD)).Stat(out statstg, grfStatFlag); }
internal static int CopyTo(ref StreamDescriptor pSD, IntPtr pstm, long cb, out long cbRead, out long cbWritten) { return((StreamAsIStream.FromSD(ref pSD)).CopyTo(pstm, cb, out cbRead, out cbWritten)); }
internal static int UnlockRegion(ref StreamDescriptor pSD, long libOffset, long cb, uint dwLockType) { return (StreamAsIStream.FromSD(ref pSD)).UnlockRegion(libOffset, cb, dwLockType); }
internal static int Revert(ref StreamDescriptor pSD) { return((StreamAsIStream.FromSD(ref pSD)).Revert()); }
internal static int Write(ref StreamDescriptor pSD, byte[] buffer, uint cb, out uint cbWritten) { return (StreamAsIStream.FromSD(ref pSD)).Write(buffer, cb, out cbWritten); }
internal static int SetSize(ref StreamDescriptor pSD, long value) { return((StreamAsIStream.FromSD(ref pSD)).SetSize(value)); }
internal static int CanWrite(ref StreamDescriptor pSD, out bool canWrite) { return (StreamAsIStream.FromSD(ref pSD)).CanWrite(out canWrite); }
internal static int UnlockRegion(ref StreamDescriptor pSD, long libOffset, long cb, uint dwLockType) { return((StreamAsIStream.FromSD(ref pSD)).UnlockRegion(libOffset, cb, dwLockType)); }
internal static int CanSeek(ref StreamDescriptor pSD, out bool canSeek) { return (StreamAsIStream.FromSD(ref pSD)).CanSeek(out canSeek); }
internal static int CanSeek(ref StreamDescriptor pSD, out bool canSeek) { return((StreamAsIStream.FromSD(ref pSD)).CanSeek(out canSeek)); }
internal static IntPtr IStreamFrom(System.IO.Stream stream) { if (stream == null) { throw new System.ArgumentNullException("stream"); } IntPtr pStream = IntPtr.Zero; StreamAsIStream sais = new StreamAsIStream(stream); StreamDescriptor sd = new StreamDescriptor(); sd.pfnDispose = StaticPtrs.pfnDispose; sd.pfnClone = StaticPtrs.pfnClone; sd.pfnCommit = StaticPtrs.pfnCommit; sd.pfnCopyTo = StaticPtrs.pfnCopyTo; sd.pfnLockRegion = StaticPtrs.pfnLockRegion; sd.pfnRead = StaticPtrs.pfnRead; sd.pfnRevert = StaticPtrs.pfnRevert; unsafe { sd.pfnSeek = StaticPtrs.pfnSeek; } sd.pfnSetSize = StaticPtrs.pfnSetSize; sd.pfnStat = StaticPtrs.pfnStat; sd.pfnUnlockRegion = StaticPtrs.pfnUnlockRegion; sd.pfnWrite = StaticPtrs.pfnWrite; sd.pfnCanWrite = StaticPtrs.pfnCanWrite; sd.pfnCanSeek = StaticPtrs.pfnCanSeek; sd.m_handle = System.Runtime.InteropServices.GCHandle.Alloc(sais, System.Runtime.InteropServices.GCHandleType.Normal); HRESULT.Check(UnsafeNativeMethods.MilCoreApi.MILCreateStreamFromStreamDescriptor(ref sd, out pStream)); return pStream; }
internal static StreamAsIStream FromSD(ref StreamDescriptor sd) { Debug.Assert(((IntPtr)sd.m_handle) != IntPtr.Zero, "Stream is disposed."); System.Runtime.InteropServices.GCHandle handle = (System.Runtime.InteropServices.GCHandle)(sd.m_handle); return (StreamAsIStream)(handle.Target); }