diff --git a/host/platform/Windows/CMakeLists.txt b/host/platform/Windows/CMakeLists.txt index d689001c..46452fc3 100644 --- a/host/platform/Windows/CMakeLists.txt +++ b/host/platform/Windows/CMakeLists.txt @@ -24,6 +24,7 @@ target_link_libraries(platform_Windows capture userenv + ntdll wtsapi32 psapi shlwapi diff --git a/host/platform/Windows/include/windows/delay.h b/host/platform/Windows/include/windows/delay.h index 8672552f..60055516 100644 --- a/host/platform/Windows/include/windows/delay.h +++ b/host/platform/Windows/include/windows/delay.h @@ -20,14 +20,6 @@ #include -typedef NTSTATUS (__stdcall *ZwSetTimerResolution_t)(ULONG RequestedResolution, - BOOLEAN Set, PULONG ActualResolution); -extern ZwSetTimerResolution_t ZwSetTimerResolution; - -typedef NTSTATUS (__stdcall *NtDelayExecution_t)(BOOL Alertable, - PLARGE_INTEGER DelayInterval); -extern NtDelayExecution_t NtDelayExecution; - void delayInit(void); // like sleep but more accurate diff --git a/host/platform/Windows/src/delay.c b/host/platform/Windows/src/delay.c index c8e91d2f..92eefc70 100644 --- a/host/platform/Windows/src/delay.c +++ b/host/platform/Windows/src/delay.c @@ -21,25 +21,22 @@ #include "windows/delay.h" #include "common/debug.h" -NtDelayExecution_t NtDelayExecution; -ZwSetTimerResolution_t ZwSetTimerResolution; +NTSYSCALLAPI NTSTATUS NTAPI NtDelayExecution( + _In_ BOOLEAN Alertable, + _In_opt_ PLARGE_INTEGER DelayInterval +); + +NTSYSCALLAPI NTSTATUS NTAPI NtSetTimerResolution( + _In_ ULONG DesiredTime, + _In_ BOOLEAN SetResolution, + _Out_ PULONG ActualTime +); void delayInit(void) { - HMODULE ntdll = GetModuleHandle("ntdll.dll"); - NtDelayExecution = (NtDelayExecution_t) - GetProcAddress(ntdll, "NtDelayExecution"); - - // Increase the timer resolution - ZwSetTimerResolution = (ZwSetTimerResolution_t) - GetProcAddress(ntdll, "ZwSetTimerResolution"); - - if (ZwSetTimerResolution) - { - ULONG actualResolution; - ZwSetTimerResolution(1, true, &actualResolution); - DEBUG_INFO("System timer resolution: %lu ns", actualResolution * 100); - } + ULONG actualResolution; + NtSetTimerResolution(1, true, &actualResolution); + DEBUG_INFO("System timer resolution: %.1f μs", actualResolution / 10.0); } void delayExecution(float ms)