using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Contains information about a file that the OpenFile function opened or attempted to open.
// typedef struct _OFSTRUCT { BYTE cBytes; BYTE fFixedDisk; WORD nErrCode; WORD Reserved1; WORD Reserved2; CHAR
// szPathName[OFS_MAXPATHNAME];} OFSTRUCT,
// *POFSTRUCT; https://msdn.microsoft.com/en-us/library/windows/desktop/aa365282(v=vs.85).aspx
[PInvokeData("WinBase.h", MSDNShortId = "aa365282")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct OFSTRUCT
{
/// The size of the structure, in bytes.
public byte cBytes;
/// If this member is , the file is on a hard (fixed) disk. Otherwise, it is not.
[MarshalAs(UnmanagedType.U1)]
public bool fFixedDisk;
/// The MS-DOS error code if the OpenFile function failed.
public ushort nErrCode;
/// Reserved; do not use.
public ushort Reserved1;
/// Reserved; do not use.
public ushort Reserved2;
/// The path and file name of the file.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szPathName;
/// Initializes a new instance of the struct.
/// The path and file name of the file.
/// If this member is , the file is on a hard (fixed) disk. Otherwise, it is not.
public OFSTRUCT(string pathName, bool fixedDisk = false)
{
cBytes = (byte)Marshal.SizeOf(typeof(OFSTRUCT));
fFixedDisk = fixedDisk;
nErrCode = Reserved1 = Reserved2 = 0;
szPathName = pathName;
}
/// Provides a default instance with size field set.
public static readonly OFSTRUCT Default = new(string.Empty);
}
}