using System;
namespace Vanara.PInvoke
{
/// Flags that determine the minimum supported client(s) for a P/Invoke function.
[Flags]
public enum PInvokeClient
{
/// No minimum (default).
None = 0,
/// Windows 2000
Windows2000 = 0x1,
/// Windows XP
WindowsXP = 0x3,
/// Windows XP SP2
WindowsXP_SP2 = 0x7,
/// Windows Vista
WindowsVista = 0xF,
/// Windows Vista SP2
WindowsVista_SP2 = 0x1F,
/// Windows 7
Windows7 = 0x3F,
/// Windows 8
Windows8 = 0x7F,
/// Windows 8.1
Windows81 = 0xFF,
/// Windows 10
Windows10 = 0x1FF
}
/// Captures information about P/Invoke calls.
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Event |
AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Method |
AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
public class PInvokeDataAttribute : Attribute
{
/// Initializes a new instance of the class.
/// The header.
public PInvokeDataAttribute(string header) => Header = header;
/// Gets or sets the DLL in which this element is defined.
/// The DLL file name without the path (e.g. "advapi32.dll").
public string Dll { get; set; }
/// Gets or sets the header in which this element is defined.
/// The header file name without the path (e.g. "winuser.h").
public string Header { get; set; }
/// Gets or sets the minimum supported client.
/// The minimum supported client.
public PInvokeClient MinClient { get; set; }
/// Gets or sets the MSDN short identifier.
/// The MSDN short identifier. This is a unique 8-character alphanumeric string used for Microsoft documentation.
public string MSDNShortId { get; set; }
}
}
namespace Vanara.Extensions
{
/// Extension methods for .
public static class PInvokeClientExtensions
{
/// Determines whether the running OS is minimally the one specified.
/// The OS version to check.
/// if the running OS is minimally the specified client; otherwise, .
public static bool IsPlatformSupported(this PInvoke.PInvokeClient client)
{
var osVer = System.Environment.OSVersion.Version;
switch (client)
{
case PInvoke.PInvokeClient.None:
return true;
case PInvoke.PInvokeClient.Windows2000:
return osVer.Major >= 5;
case PInvoke.PInvokeClient.WindowsXP:
return osVer >= new Version(5, 1);
case PInvoke.PInvokeClient.WindowsXP_SP2:
return osVer >= new Version(5, 1, 2600, 2180);
case PInvoke.PInvokeClient.WindowsVista:
return osVer.Major >= 6;
case PInvoke.PInvokeClient.WindowsVista_SP2:
return osVer >= new Version(6, 0, 6002);
case PInvoke.PInvokeClient.Windows7:
return osVer >= new Version(6, 1);
case PInvoke.PInvokeClient.Windows8:
return osVer >= new Version(6, 2);
case PInvoke.PInvokeClient.Windows81:
return osVer >= new Version(6, 3);
case PInvoke.PInvokeClient.Windows10:
return osVer.Major >= 10;
default:
return false;
}
}
}
}