using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using STATSTG = System.Runtime.InteropServices.ComTypes.STATSTG;
namespace Vanara.PInvoke;
public static partial class Shell32
{
/// Exposes methods to manage input/outpout (I/O) to an asynchronous stream.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nn-shobjidl-istreamasync
[ComImport, Guid("fe0b6665-e0ca-49b9-a178-2b5cb48d92a5"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public unsafe interface IStreamAsync : IStream
{
///
new void Read(byte[] pv, int cb, IntPtr pcbRead);
///
new void Write(byte[] pv, int cb, IntPtr pcbWritten);
///
new void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition);
///
new void SetSize(long libNewSize);
///
new void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten);
///
new void Commit(int grfCommitFlags);
///
new void Revert();
///
new void LockRegion(long libOffset, long cb, int dwLockType);
///
new void UnlockRegion(long libOffset, long cb, int dwLockType);
///
new void Stat(out STATSTG pstatstg, int grfStatFlag);
///
new void Clone(out IStream ppstm);
///
/// Reads information from a stream asynchronously. For example, the Shell implements this interface on file items when
/// transferring them asynchronously.
///
///
/// Type: void*
///
/// When this method returns successfully, returns a buffer that is cb bytes long and contains pcbRead bytes of information from
/// the read operation.
///
///
///
/// Type: DWORD
/// The number of bytes to read from the stream.
///
///
/// Type: LPDWORD
///
/// Pointer to a DWORD value that, when this method returns successfully, states the actual number of bytes read to the
/// buffer pointed to by pv. This value can be NULL.
///
///
///
/// Type: LPOVERLAPPED
/// A pointer to an OVERLAPPED structure that contains information used in the asynchronous read operation.
///
///
///
/// IStreamAsync::ReadAsync should reset the event specified by the hEvent member of the OVERLAPPED structure to a
/// nonsignaled state when it begins the input/output (I/O) operation.
///
/// This method has been implemented in the Shell as a thin wrapper around the public ReadFile API.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-istreamasync-readasync HRESULT ReadAsync( void *pv,
// DWORD cb, LPDWORD pcbRead, LPOVERLAPPED lpOverlapped );
void ReadAsync([Out] IntPtr pv, uint cb, out uint pcbRead, [In] NativeOverlapped* lpOverlapped);
///
/// Writes information to a stream asynchronously. For example, the Shell implements this method on file items when transferring
/// them asynchronously.
///
///
/// Type: const void*
/// A pointer to a buffer of size cb bytes that contains the information to be written to the stream.
///
///
/// Type: DWORD
/// The size of the buffer pointed to by lpBuffer, in bytes.
///
///
/// Type: LPDWORD
///
/// Pointer to a DWORD value that, when the method returns successfully, states the actual number of bytes written to the
/// stream. This value can be NULL if this information is not needed.
///
///
///
/// Type: LPOVERLAPPED
/// A pointer to an OVERLAPPED structure that contains information used in the asynchronous write operation.
///
///
/// WriteAsync should reset the event specified by the hEvent member of the OVERLAPPED structure to a nonsignaled
/// state when it begins the input/output (I/O) operation.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-istreamasync-writeasync HRESULT WriteAsync( const
// void *lpBuffer, DWORD cb, LPDWORD pcbWritten, LPOVERLAPPED lpOverlapped );
void WriteAsync([In] IntPtr lpBuffer, uint cb, out uint pcbWritten, [In] NativeOverlapped* lpOverlapped);
/// Retrieves the results of an overlapped operation.
///
/// Type: LPOVERLAPPED*
/// A pointer to the OVERLAPPED structure that was specified when the overlapped operation was started.
///
///
/// Type: LPDWORD
/// When this method returns, contains the number of bytes that were actually transferred by a read or write operation.
///
///
/// Type: BOOL
///
/// If TRUE the method does not return until the operation has been completed. If FALSE and an operation is
/// pending, the method returns the HRESULT equivalent to ERROR_IO_INCOMPLETE.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-istreamasync-overlappedresult HRESULT
// OverlappedResult( LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfBytesTransferred, BOOL bWait );
void OverlappedResult([In] NativeOverlapped* lpOverlapped, out uint lpNumberOfBytesTransferred, [MarshalAs(UnmanagedType.Bool)] bool bWait);
/// Marks all pending input/output (I/O) operations as canceled.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-istreamasync-cancelio HRESULT CancelIo();
void CancelIo();
}
/// Exposes a method that determines the sector size as an aid to byte alignment.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nn-shobjidl-istreamunbufferedinfo
[PInvokeData("shobjidl.h", MSDNShortId = "NN:shobjidl.IStreamUnbufferedInfo")]
[ComImport, Guid("8a68fdda-1fdc-4c20-8ceb-416643b5a625"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IStreamUnbufferedInfo
{
///
/// Retrieves the number of bytes per sector on the disk currently being used. When using unbuffered input/output (I/O), it is
/// important to know the size of the sectors on the disk being read in order to ensure proper byte alignment.
///
///
/// Type: ULONG*
///
/// When this method returns successfully, contains a pointer to a ULONG value that represents the number of bytes per
/// sector for the disk.
///
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl/nf-shobjidl-istreamunbufferedinfo-getsectorsize HRESULT
// GetSectorSize( ULONG *pcbSectorSize );
[PreserveSig]
HRESULT GetSectorSize(out uint pcbSectorSize);
}
}