using System.Runtime.InteropServices; using Titano.Core.IO; namespace Titano.Core.Windows.Interop; /// IStream over a file through SHCreateStreamOnFileEx. internal static partial class ShellStream { private const uint STGM_READ = 0x0; private const uint STGM_SHARE_DENY_NONE = 0x40; private const uint FILE_ATTRIBUTE_NORMAL = 0x80; /// /// Opens read-only while letting other processes read and write it (FileShare.ReadWrite), /// so a camera tether or a copy in progress is never blocked. Returns an owned IStream pointer the caller must /// . Failures surface as the matching .NET exception (FileNotFoundException, …). /// public static nint OpenRead(string path) { var hr = SHCreateStreamOnFileEx(LongPath.Normalize(path), STGM_READ | STGM_SHARE_DENY_NONE, FILE_ATTRIBUTE_NORMAL, 0, 0, out var stream); Marshal.ThrowExceptionForHR(hr); return stream; } [LibraryImport("shlwapi.dll", StringMarshalling = StringMarshalling.Utf16)] private static partial int SHCreateStreamOnFileEx(string file, uint mode, uint attributes, int create, nint template, out nint stream); }