From f6b7c3892d4d12eb840cfa0663ea8a33515535c9 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 28 Nov 2018 08:53:05 -0700 Subject: [PATCH] Added new Win10 functions --- PInvoke/Kernel32/SysInfoApi.cs | 45 ++++++++++++++++++++++++++++++++++++++++ PInvoke/Kernel32/WinBase.Comm.cs | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/PInvoke/Kernel32/SysInfoApi.cs b/PInvoke/Kernel32/SysInfoApi.cs index 695f878d..097f93ef 100644 --- a/PInvoke/Kernel32/SysInfoApi.cs +++ b/PInvoke/Kernel32/SysInfoApi.cs @@ -1599,6 +1599,51 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetSystemTimeAdjustment(out uint lpTimeAdjustment, out uint lpTimeIncrement, [MarshalAs(UnmanagedType.Bool)] out bool lpTimeAdjustmentDisabled); + /// + /// + /// Determines whether the system is applying periodic, programmed time adjustments to its time-of-day clock, and obtains the value + /// and period of any such adjustments. + /// + /// + /// + /// Returns the adjusted clock update frequency. + /// + /// + /// Returns the clock update frequency. + /// + /// + /// Returns an indicator which specifies whether the time adjustment is enabled. + /// + /// A value of TRUE indicates that periodic adjustment is disabled. In this case, the system may attempt to keep the + /// time-of-day clock in sync using its own internal mechanisms. This may cause time-of-day to periodically jump to the "correct time." + /// + /// + /// A value of FALSE indicates that periodic, programmed time adjustment is being used to serialize time-of-day, and the + /// system will not interfere or attempt to synchronize time-of-day on its own. + /// + /// + /// + /// 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. + /// + /// + /// + /// This function is used in algorithms that synchronize the time-of-day with another time source, using a programmed clock + /// adjustment. To do this, the system computes the adjusted clock update frequency, and then this function allows the caller to + /// obtain that value. + /// + /// + /// Note For a complete code sample on how to enable system-time privileges, adjust the system clock, and display clock + /// values, see SetSystemTimeAdjustmentPrecise. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getsystemtimeadjustmentprecise + // BOOL GetSystemTimeAdjustmentPrecise( PDWORD64 lpTimeAdjustment, PDWORD64 lpTimeIncrement, PBOOL lpTimeAdjustmentDisabled ); + [DllImport(Lib.Api, SetLastError = true, ExactSpelling = true)] + [PInvokeData("sysinfoapi.h", MSDNShortId = "95EEE23D-01D8-49E1-BA64-49C07E8B1619")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetSystemTimeAdjustmentPrecise(out ulong lpTimeAdjustment, out ulong lpTimeIncrement, [MarshalAs(UnmanagedType.Bool)] out bool lpTimeAdjustmentDisabled); + /// Retrieves the current system date and time. The information is in Coordinated Universal Time (UTC) format. /// /// A pointer to a FILETIME structure to receive the current system date and time in UTC format. diff --git a/PInvoke/Kernel32/WinBase.Comm.cs b/PInvoke/Kernel32/WinBase.Comm.cs index c4bf318a..40534712 100644 --- a/PInvoke/Kernel32/WinBase.Comm.cs +++ b/PInvoke/Kernel32/WinBase.Comm.cs @@ -638,6 +638,49 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetCommModemStatus([In] HFILE hFile, out COMM_MODEM_STATUS lpModemStat); + /// + /// Gets an array that contains the well-formed COM ports. + /// + /// This function obtains the COM port numbers from the HKLM\Hardware\DeviceMap\SERIALCOMM registry key and then writes them + /// to a caller-supplied array. If the array is too small, the function gets the necessary size. + /// + /// Note If new entries are added to the registry key, the necessary size can change between API calls. + /// + /// + /// An array for the port numbers. + /// + /// + /// The length of the array in the lpPortNumbers parameter. + /// + /// + /// The number of port numbers written to the lpPortNumbers or the length of the array required for the port numbers. + /// + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_SUCCESS + /// The call succeeded. The lpPortNumbers array was large enough for the result. + /// + /// + /// ERROR_MORE_DATA + /// The lpPortNumbers array was too small to contain all available port numbers. + /// + /// + /// ERROR_FILE_NOT_FOUND + /// There are no comm ports available. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getcommports + // ULONG GetCommPorts( PULONG lpPortNumbers, ULONG uPortNumbersCount, PULONG puPortNumbersFound ); + [DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true)] + [PInvokeData("winbase.h", MSDNShortId = "8E57FB62-D7A0-4B47-942B-E33E0B7A37B1", MinClient = PInvokeClient.Windows10)] + public static extern Win32Error GetCommPorts([In, Out] uint[] lpPortNumbers, uint uPortNumbersCount, out uint puPortNumbersFound); + /// Retrieves information about the communications properties for a specified communications device. /// A handle to the communications device. The CreateFile function returns this handle. ///