From 326692ab25f354c9ceceae615c851ac35dd049b5 Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 27 Oct 2022 13:14:24 -0600 Subject: [PATCH] Overloadded SetWaitableTimer and SetWaitableTimerEx to accept a `long` value for the lpDueTime param. --- PInvoke/Kernel32/SynchApi.cs | 129 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/PInvoke/Kernel32/SynchApi.cs b/PInvoke/Kernel32/SynchApi.cs index b30bb412..289cead5 100644 --- a/PInvoke/Kernel32/SynchApi.cs +++ b/PInvoke/Kernel32/SynchApi.cs @@ -1573,6 +1573,51 @@ namespace Vanara.PInvoke public static extern bool SetWaitableTimer([In] SafeWaitableTimerHandle hTimer, in FILETIME pDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, [In, Optional] IntPtr lpArgToCompletionRoutine, [MarshalAs(UnmanagedType.Bool)] bool fResume = false); + /// + /// Activates the specified waitable timer. When the due time arrives, the timer is signaled and the thread that set the timer calls + /// the optional completion routine. + /// + /// + /// A handle to the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle. + /// + /// The handle must have the TIMER_MODIFY_STATE access right. For more information, see Synchronization Object Security and + /// Access Rights. + /// + /// + /// + /// The time after which the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by + /// the FILETIME structure. Positive values indicate absolute time. Be sure to use a UTC-based absolute time, as the system + /// uses UTC-based time internally. Negative values indicate relative time. The actual timer accuracy depends on the capability of + /// your hardware. For more information about UTC-based time, see System Time. + /// + /// + /// The period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once. If lPeriod is greater than zero, the + /// timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the + /// CancelWaitableTimer function or reset using SetWaitableTimer. If lPeriod is less than zero, the function fails. + /// + /// + /// A pointer to an optional completion routine. The completion routine is application-defined function of type + /// PTIMERAPCROUTINE to be executed when the timer is signaled. For more information on the timer callback function, see + /// TimerAPCProc. For more information about APCs and thread pool threads, see Remarks. + /// + /// A pointer to a structure that is passed to the completion routine. + /// + /// If this parameter is TRUE, restores a system in suspended power conservation mode when the timer state is set to signaled. + /// Otherwise, the system is not restored. If the system does not support a restore, the call succeeds, but GetLastError + /// returns ERROR_NOT_SUPPORTED. + /// + /// + /// 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 SetWaitableTimer( _In_ HANDLE hTimer, _In_ const LARGE_INTEGER *pDueTime, _In_ LONG lPeriod, _In_opt_ PTIMERAPCROUTINE + // pfnCompletionRoutine, _In_opt_ LPVOID lpArgToCompletionRoutine, _In_ BOOL fResume); https://msdn.microsoft.com/en-us/library/windows/desktop/ms686289(v=vs.85).aspx + [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("WinBase.h", MSDNShortId = "ms686289")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetWaitableTimer([In] SafeWaitableTimerHandle hTimer, in long pDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, + [In, Optional] IntPtr lpArgToCompletionRoutine, [MarshalAs(UnmanagedType.Bool)] bool fResume = false); + /// /// Activates the specified waitable timer and provides context information for the timer. When the due time arrives, the timer is /// signaled and the thread that set the timer calls the optional completion routine. @@ -1615,6 +1660,48 @@ namespace Vanara.PInvoke public static extern bool SetWaitableTimerEx([In] SafeWaitableTimerHandle hTimer, in FILETIME lpDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, [In, Optional] IntPtr lpArgToCompletionRoutine, [In] REASON_CONTEXT WakeContext, uint TolerableDelay); + /// + /// Activates the specified waitable timer and provides context information for the timer. When the due time arrives, the timer is + /// signaled and the thread that set the timer calls the optional completion routine. + /// + /// + /// A handle to the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle. + /// + /// The handle must have the TIMER_MODIFY_STATE access right. For more information, see Synchronization Object Security and + /// Access Rights. + /// + /// + /// + /// The time after which the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by + /// the FILETIME structure. Positive values indicate absolute time. Be sure to use a UTC-based absolute time, as the system + /// uses UTC-based time internally. Negative values indicate relative time. The actual timer accuracy depends on the capability of + /// your hardware. For more information about UTC-based time, see System Time. + /// + /// + /// The period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once. If lPeriod is greater than zero, the + /// timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the + /// CancelWaitableTimer function or reset using SetWaitableTimerEx. If lPeriod is less than zero, the function fails. + /// + /// + /// A pointer to an optional completion routine. The completion routine is application-defined function of type + /// PTIMERAPCROUTINE to be executed when the timer is signaled. For more information on the timer callback function, see + /// TimerAPCProc. For more information about APCs and thread pool threads, see Remarks. + /// + /// A pointer to a structure that is passed to the completion routine. + /// Pointer to a REASON_CONTEXT structure that contains context information for the timer. + /// The tolerable delay for expiration time, in milliseconds. + /// + /// 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 SetWaitableTimerEx( _In_ HANDLE hTimer, _In_ const LARGE_INTEGER *lpDueTime, _In_ LONG lPeriod, _In_ PTIMERAPCROUTINE + // pfnCompletionRoutine, _In_ LPVOID lpArgToCompletionRoutine, _In_ PREASON_CONTEXT WakeContext, _In_ ULONG TolerableDelay); https://msdn.microsoft.com/en-us/library/windows/desktop/dd405521(v=vs.85).aspx + [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("WinBase.h", MSDNShortId = "dd405521")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetWaitableTimerEx([In] SafeWaitableTimerHandle hTimer, in long lpDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, + [In, Optional] IntPtr lpArgToCompletionRoutine, [In] REASON_CONTEXT WakeContext, uint TolerableDelay); + /// /// Activates the specified waitable timer and provides context information for the timer. When the due time arrives, the timer is /// signaled and the thread that set the timer calls the optional completion routine. @@ -1657,6 +1744,48 @@ namespace Vanara.PInvoke public static extern bool SetWaitableTimerEx([In] SafeWaitableTimerHandle hTimer, in FILETIME lpDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, [In, Optional] IntPtr lpArgToCompletionRoutine, [Optional] IntPtr WakeContext, uint TolerableDelay); + /// + /// Activates the specified waitable timer and provides context information for the timer. When the due time arrives, the timer is + /// signaled and the thread that set the timer calls the optional completion routine. + /// + /// + /// A handle to the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle. + /// + /// The handle must have the TIMER_MODIFY_STATE access right. For more information, see Synchronization Object Security and + /// Access Rights. + /// + /// + /// + /// The time after which the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by + /// the FILETIME structure. Positive values indicate absolute time. Be sure to use a UTC-based absolute time, as the system + /// uses UTC-based time internally. Negative values indicate relative time. The actual timer accuracy depends on the capability of + /// your hardware. For more information about UTC-based time, see System Time. + /// + /// + /// The period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once. If lPeriod is greater than zero, the + /// timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the + /// CancelWaitableTimer function or reset using SetWaitableTimerEx. If lPeriod is less than zero, the function fails. + /// + /// + /// A pointer to an optional completion routine. The completion routine is application-defined function of type + /// PTIMERAPCROUTINE to be executed when the timer is signaled. For more information on the timer callback function, see + /// TimerAPCProc. For more information about APCs and thread pool threads, see Remarks. + /// + /// A pointer to a structure that is passed to the completion routine. + /// Pointer to a REASON_CONTEXT structure that contains context information for the timer. + /// The tolerable delay for expiration time, in milliseconds. + /// + /// 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 SetWaitableTimerEx( _In_ HANDLE hTimer, _In_ const LARGE_INTEGER *lpDueTime, _In_ LONG lPeriod, _In_ PTIMERAPCROUTINE + // pfnCompletionRoutine, _In_ LPVOID lpArgToCompletionRoutine, _In_ PREASON_CONTEXT WakeContext, _In_ ULONG TolerableDelay); https://msdn.microsoft.com/en-us/library/windows/desktop/dd405521(v=vs.85).aspx + [DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)] + [PInvokeData("WinBase.h", MSDNShortId = "dd405521")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool SetWaitableTimerEx([In] SafeWaitableTimerHandle hTimer, in long lpDueTime, [Optional] int lPeriod, [Optional] TimerAPCProc pfnCompletionRoutine, + [In, Optional] IntPtr lpArgToCompletionRoutine, [Optional] IntPtr WakeContext, uint TolerableDelay); + /// Signals one object and waits on another object as a single operation. /// /// A handle to the object to be signaled. This object can be a semaphore, a mutex, or an event.