From b7bd9f5950d9712217e2dd5b40f2aeb82294e3c7 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 1 Dec 2020 01:41:22 -0500 Subject: refactor io --- common/rawaccel-io.hpp | 53 ++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 38 deletions(-) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index e8641d1..4159b60 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -5,18 +5,16 @@ #define NOMINMAX #include +#include "rawaccel-io-def.h" #include "rawaccel-settings.h" #include "rawaccel-error.hpp" -#define RA_READ CTL_CODE(0x8888, 0x888, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) -#define RA_WRITE CTL_CODE(0x8888, 0x889, METHOD_BUFFERED, FILE_ANY_ACCESS) - #pragma warning(push) #pragma warning(disable:4245) // int -> DWORD conversion while passing CTL_CODE namespace rawaccel { - settings read() { + void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) { HANDLE ra_handle = INVALID_HANDLE_VALUE; ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); @@ -25,18 +23,17 @@ namespace rawaccel { throw install_error(); } - settings args; DWORD dummy; BOOL success = DeviceIoControl( ra_handle, - RA_READ, - NULL, // input buffer - 0, // input buffer size - &args, // output buffer - sizeof(settings), // output buffer size - &dummy, // bytes returned - NULL // overlapped structure + code, + in, + in_size, + out, + out_size, + &dummy, // bytes returned + NULL // overlapped structure ); CloseHandle(ra_handle); @@ -44,38 +41,18 @@ namespace rawaccel { if (!success) { throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); } + } + settings read() { + settings args; + io_control(RA_READ, NULL, 0, &args, sizeof(settings)); return args; } void write(const settings& args) { - 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 install_error(); - } - - DWORD dummy; - - BOOL success = DeviceIoControl( - ra_handle, - RA_WRITE, - const_cast(&args), // input buffer - sizeof(settings), // input buffer size - 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"); - } + auto in_ptr = const_cast(&args); + io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0); } } -- cgit v1.2.3 From 7d14daf1d5fce4d09471a3abe2aca49cf7680816 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 2 Dec 2020 05:25:19 -0500 Subject: embed version info into assemblies check app versions against lib, lib against driver add an 'about' dialog which displays version details, accessible from menu refactor error handling + add check for negative offset --- common/rawaccel-io.hpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 4159b60..703ea92 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -7,6 +7,7 @@ #include "rawaccel-io-def.h" #include "rawaccel-settings.h" +#include "rawaccel-version.h" #include "rawaccel-error.hpp" #pragma warning(push) @@ -55,6 +56,12 @@ namespace rawaccel { io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0); } + version_t get_version() { + version_t ver; + io_control(RA_GET_VERSION, NULL, 0, &ver, sizeof(version_t)); + return ver; + } + } #pragma warning(pop) -- cgit v1.2.3