Created
April 16, 2017 14:35
-
-
Save hydranix/b8af0c197a1cc11429da600c33c15418 to your computer and use it in GitHub Desktop.
[Undocumented WinAPI] Timer Resolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Oskar Dahlberg's post at: | |
// http://stackoverflow.com/a/31411628/4725495 | |
#include <Windows.h> | |
static NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval) = (NTSTATUS(__stdcall*)(BOOL, PLARGE_INTEGER)) GetProcAddress(GetModuleHandle("ntdll.dll"), "NtDelayExecution"); | |
static NTSTATUS(__stdcall *ZwSetTimerResolution)(IN ULONG RequestedResolution, IN BOOLEAN Set, OUT PULONG ActualResolution) = (NTSTATUS(__stdcall*)(ULONG, BOOLEAN, PULONG)) GetProcAddress(GetModuleHandle("ntdll.dll"), "ZwSetTimerResolution"); | |
static void SleepShort(float milliseconds) { | |
static bool once = true; | |
if (once) { | |
ULONG actualResolution; | |
ZwSetTimerResolution(1, true, &actualResolution); | |
once = false; | |
} | |
LARGE_INTEGER interval; | |
interval.QuadPart = -1 * (int)(milliseconds * 10000.0f); | |
NtDelayExecution(false, &interval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment