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
|
#include <iostream>
#define NOMINMAX
#include <Windows.h>
#include <rawaccel-userspace.hpp>
#define RA_WRITE CTL_CODE(0x8888, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS)
namespace ra = rawaccel;
void write(ra::variables vars) {
HANDLE ra_handle = INVALID_HANDLE_VALUE;
ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0);
if (ra_handle == INVALID_HANDLE_VALUE) {
throw std::system_error(GetLastError(), std::system_category(), "CreateFile failed");
}
DWORD dummy;
BOOL success = DeviceIoControl(
ra_handle,
RA_WRITE,
&vars,
sizeof(ra::variables),
NULL, // output buffer
0, // output buffer size
&dummy, // bytes returned
NULL // overlapped structure
);
CloseHandle(ra_handle);
if (!success) {
throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed");
}
}
int main(int argc, char** argv) {
try {
write(ra::parse(argc, argv));
}
catch (std::domain_error e) {
std::cerr << e.what() << '\n';
return ra::INVALID_ARGUMENT;
}
catch (std::system_error e) {
std::cerr << "Error: " << e.what() << " (" << e.code() << ")\n";
return ra::SYSTEM_ERROR;
}
}
|