Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
61 lines (52 loc) · 1.92 KB
/
Copy pathmain.c
File metadata and controls
61 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Written by J. Dijkstra (abort@digitalise.net), 2012
Feel free to use this example in any format/project (no licensing), although using these API's will be at your own risk :).
*/
#include <Windows.h>
#pragma warning(disable: 4005)
#include <ntstatus.h>
#pragma warning(default: 4005)
#include <stdio.h>
typedef NTSTATUS (NTAPI* pSetTimerResolution)(ULONG RequestedResolution, BOOLEAN Set, PULONG ActualResolution);
typedef NTSTATUS (NTAPI* pQueryTimerResolution)(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution);
int main(void)
{
NTSTATUS status;
pSetTimerResolution setFunction;
pQueryTimerResolution queryFunction;
ULONG minResolution, maxResolution, actualResolution;
const HINSTANCE hLibrary = LoadLibrary("NTDLL.dll");
if (hLibrary == NULL)
{
printf("Failed to load NTDLL.dll (%d)\n", GetLastError());
return 1;
}
queryFunction = (pQueryTimerResolution)GetProcAddress(hLibrary, "NtQueryTimerResolution");
if (queryFunction == NULL)
{
printf("NtQueryTimerResolution is null (%d)\n", GetLastError());
return 1;
}
queryFunction(&minResolution, &maxResolution, &actualResolution);
printf("Win32 Timer Resolution:\n\tMinimum Value:\t%u\n\tMaximum Value:\t%u\n\tActual Value:\t%u\n\n", minResolution, maxResolution, actualResolution);
setFunction = (pSetTimerResolution)GetProcAddress(hLibrary, "NtSetTimerResolution");
if (setFunction == NULL)
{
printf("NtSetTimerResolution is null (%d)\n", GetLastError());
return 1;
}
printf("Setting Timer Resolution to the maximum value (%d)...\n", maxResolution);
status = setFunction(maxResolution, TRUE, &actualResolution);
if (status == STATUS_SUCCESS)
{
printf("Success! (Current resolution: %d)\n", actualResolution);
return 0;
}
if (status == STATUS_TIMER_RESOLUTION_NOT_SET)
{
printf("Timer not set (Return Code: %d)\n", status);
return 2;
}
printf("Failed, Return Value: %d (Error Code: %d)\n", status, GetLastError());
return 1;
}