using System.Runtime.InteropServices; using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; namespace Vanara.PInvoke { public static partial class Kernel32 { /// Converts MS-DOS date and time values to a file time. /// /// The MS-DOS date. The date is a packed value with the following format. /// /// /// /// Bits /// Description /// /// /// 0-4 /// Day of the month (1–31) /// /// /// 5-8 /// Month (1 = January, 2 = February, and so on) /// /// /// 9-15 /// Year offset from 1980 (add 1980 to get actual year) /// /// /// /// /// /// The MS-DOS time. The time is a packed value with the following format. /// /// /// /// Bits /// Description /// /// /// 0-4 /// Second divided by 2 /// /// /// 5-10 /// Minute (0–59) /// /// /// 11-15 /// Hour (0–23 on a 24-hour clock) /// /// /// /// /// A pointer to a FILETIME structure that receives the converted file time. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI DosDateTimeToFileTime( _In_ WORD wFatDate, _In_ WORD wFatTime, _Out_ LPFILETIME lpFileTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724247(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724247")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DosDateTimeToFileTime(ushort wFatDate, ushort wFatTime, out FILETIME lpFileTime); /// Converts a file time to MS-DOS date and time values. /// /// A pointer to a FILETIME structure containing the file time to convert to MS-DOS date and time format. /// /// /// A pointer to a variable to receive the MS-DOS date. The date is a packed value with the following format. /// /// /// /// Bits /// Description /// /// /// 0–4 /// Day of the month (1–31) /// /// /// 5–8 /// Month (1 = January, 2 = February, etc.) /// /// /// 9-15 /// Year offset from 1980 (add 1980 to get actual year) /// /// /// /// /// /// A pointer to a variable to receive the MS-DOS time. The time is a packed value with the following format. /// /// /// /// Bits /// Description /// /// /// 0–4 /// Second divided by 2 /// /// /// 5–10 /// Minute (0–59) /// /// /// 11–15 /// Hour (0–23 on a 24-hour clock) /// /// /// /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI FileTimeToDosDateTime( _In_ const FILETIME *lpFileTime, _Out_ LPWORD lpFatDate, _Out_ LPWORD lpFatTime); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724274(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "ms724274")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FileTimeToDosDateTime(in FILETIME lpFileTime, out ushort lpFatDate, out ushort lpFatTime); /// /// Gets a range, expressed in years, for which a DYNAMIC_TIME_ZONE_INFORMATION has valid entries. Use the returned value to /// identify the specific years to request when calling GetTimeZoneInformationForYear to retrieve time zone information for a /// time zone that experiences annual boundary changes due to daylight saving time adjustments. /// /// Specifies settings for a time zone and dynamic daylight saving time. /// The year that marks the beginning of the range to pass to GetTimeZoneInformationForYear. /// The year that marks the end of the range to pass to GetTimeZoneInformationForYear. /// /// /// /// Return code/value /// Description /// /// /// ERROR_SUCCESS /// The operation succeeded. /// /// /// ERROR_FILE_NOT_FOUND /// The system cannot find the effective years. /// /// /// ERROR_INVALID_PARAMETER /// One of the parameter values is not valid. /// /// /// Any other value /// The operation failed. /// /// /// // DWORD WINAPI GetDynamicTimeZoneInformationEffectiveYears( _In_ const PDYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation, _Out_ // LPDWORD FirstYear, _Out_ LPDWORD LastYear); https://msdn.microsoft.com/en-us/library/windows/desktop/hh706894(v=vs.85).aspx [DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true)] [PInvokeData("Winbase.h", MSDNShortId = "hh706894")] public static extern Win32Error GetDynamicTimeZoneInformationEffectiveYears(in DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation, out uint FirstYear, out uint LastYear); } }