diff options
| author | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2020-07-22 19:34:13 -0400 |
| commit | 78156f34166c110fcad47aef166684b8e25ac4fa (patch) | |
| tree | b6121a5e1725639800c266c865f9067b3cd31a17 /console/console.cpp | |
| parent | Add .gitignore and .gitattributes. (diff) | |
| download | rawaccel-78156f34166c110fcad47aef166684b8e25ac4fa.tar.xz rawaccel-78156f34166c110fcad47aef166684b8e25ac4fa.zip | |
Add project files.v0.1-test
Diffstat (limited to 'console/console.cpp')
| -rw-r--r-- | console/console.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/console/console.cpp b/console/console.cpp new file mode 100644 index 0000000..6606cac --- /dev/null +++ b/console/console.cpp @@ -0,0 +1,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; + } +} |