diff options
Diffstat (limited to 'src/osd/modules/input/input_rawinput.cpp')
-rw-r--r-- | src/osd/modules/input/input_rawinput.cpp | 88 |
1 files changed, 37 insertions, 51 deletions
diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp index ecfae316d41..cfab7dcdb5a 100644 --- a/src/osd/modules/input/input_rawinput.cpp +++ b/src/osd/modules/input/input_rawinput.cpp @@ -26,7 +26,7 @@ #include "strconv.h" // MAMEOS headers -#include "winutil.h" +#include "modules/lib/osdlib.h" #include "winmain.h" #include "window.h" @@ -37,17 +37,11 @@ // MACROS //============================================================ -#ifdef UNICODE -#define UNICODE_SUFFIX "W" -#else -#define UNICODE_SUFFIX "A" -#endif - -// RawInput APIs -typedef lazy_loaded_function_p3<INT, PRAWINPUTDEVICELIST, PINT, UINT> get_rawinput_device_list_ptr; -typedef lazy_loaded_function_p5<INT, HRAWINPUT, UINT, LPVOID, PINT, UINT> get_rawinput_data_ptr; -typedef lazy_loaded_function_p4<INT, HANDLE, UINT, LPVOID, PINT> get_rawinput_device_info_ptr; -typedef lazy_loaded_function_p3<BOOL, PCRAWINPUTDEVICE, UINT, UINT> register_rawinput_devices_ptr; +// Typedefs for dynamically loaded functions +typedef UINT WINAPI (*get_rawinput_device_list_ptr)(PRAWINPUTDEVICELIST, PUINT, UINT); +typedef UINT WINAPI (*get_rawinput_data_ptr)( HRAWINPUT, UINT, LPVOID, PUINT, UINT); +typedef UINT WINAPI (*get_rawinput_device_info_ptr)(HANDLE, UINT, LPVOID, PUINT); +typedef BOOL WINAPI (*register_rawinput_devices_ptr)(PCRAWINPUTDEVICE, UINT, UINT); class safe_regkey { @@ -395,13 +389,6 @@ public: } }; -/* -register_rawinput_devices = (register_rawinput_devices_ptr)GetProcAddress(user32, "RegisterRawInputDevices"); -get_rawinput_device_list = (get_rawinput_device_list_ptr)GetProcAddress(user32, "GetRawInputDeviceList"); -get_rawinput_device_info = (get_rawinput_device_info_ptr)GetProcAddress(user32, "GetRawInputDeviceInfo" UNICODE_SUFFIX); -get_rawinput_data = (get_rawinput_data_ptr)GetProcAddress(user32, "GetRawInputData"); -*/ - //============================================================ // rawinput_module - base class for rawinput modules //============================================================ @@ -409,32 +396,33 @@ get_rawinput_data = (get_rawinput_data_ptr)GetProcAddress(user32, "GetRawInputDa class rawinput_module : public wininput_module { private: - // RawInput variables - get_rawinput_device_list_ptr get_rawinput_device_list; - get_rawinput_data_ptr get_rawinput_data; - get_rawinput_device_info_ptr get_rawinput_device_info; - register_rawinput_devices_ptr register_rawinput_devices; - std::mutex m_module_lock; + osd::dynamic_module::ptr m_user32_dll; + get_rawinput_device_list_ptr get_rawinput_device_list; + get_rawinput_data_ptr get_rawinput_data; + get_rawinput_device_info_ptr get_rawinput_device_info; + register_rawinput_devices_ptr register_rawinput_devices; + std::mutex m_module_lock; public: rawinput_module(const char *type, const char* name) - : wininput_module(type, name), - get_rawinput_device_list("GetRawInputDeviceList", L"user32.dll"), - get_rawinput_data("GetRawInputData", L"user32.dll"), - get_rawinput_device_info("GetRawInputDeviceInfoW", L"user32.dll"), - register_rawinput_devices("RegisterRawInputDevices", L"user32.dll") + : wininput_module(type, name) { } bool probe() override { - int status = get_rawinput_device_list.initialize(); - status |= get_rawinput_data.initialize(); - status |= get_rawinput_device_info.initialize(); - status |= register_rawinput_devices.initialize(); + m_user32_dll = osd::dynamic_module::open({ "user32.dll" }); + + get_rawinput_device_list = m_user32_dll->bind<get_rawinput_device_list_ptr>("GetRawInputDeviceList"); + get_rawinput_data = m_user32_dll->bind<get_rawinput_data_ptr>("GetRawInputData"); + get_rawinput_device_info = m_user32_dll->bind<get_rawinput_device_info_ptr>("GetRawInputDeviceInfoW"); + register_rawinput_devices = m_user32_dll->bind<register_rawinput_devices_ptr>("RegisterRawInputDevices"); - if (status != 0) + if (!get_rawinput_device_list || !get_rawinput_data || + !get_rawinput_device_info || !register_rawinput_devices ) + { return false; + } return true; } @@ -442,15 +430,15 @@ public: void input_init(running_machine &machine) override { // get the number of devices, allocate a device list, and fetch it - int device_count = 0; - if (get_rawinput_device_list(nullptr, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) + UINT device_count = 0; + if ((*get_rawinput_device_list)(nullptr, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) return; if (device_count == 0) return; auto rawinput_devices = std::make_unique<RAWINPUTDEVICELIST[]>(device_count); - if (get_rawinput_device_list(rawinput_devices.get(), &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) + if ((*get_rawinput_device_list)(rawinput_devices.get(), &device_count, sizeof(RAWINPUTDEVICELIST)) == -1) return; // iterate backwards through devices; new devices are added at the head @@ -478,7 +466,7 @@ public: registration.hwndTarget = osd_common_t::s_window_list.front()->platform_window<HWND>(); // register the device - register_rawinput_devices(®istration, 1, sizeof(registration)); + (*register_rawinput_devices)(®istration, 1, sizeof(registration)); } protected: @@ -488,13 +476,11 @@ protected: int init_internal() override { - // look up the entry points - int status = get_rawinput_device_list.initialize(); - status |= get_rawinput_data.initialize(); - status |= get_rawinput_device_info.initialize(); - status |= register_rawinput_devices.initialize(); - if (status != 0) + if (!get_rawinput_device_list || !get_rawinput_data || + !get_rawinput_device_info || !register_rawinput_devices ) + { return 1; + } osd_printf_verbose("RawInput: APIs detected\n"); return 0; @@ -504,13 +490,13 @@ protected: TDevice* create_rawinput_device(running_machine &machine, PRAWINPUTDEVICELIST rawinputdevice) { TDevice* devinfo; - INT name_length = 0; + UINT name_length = 0; // determine the length of the device name, allocate it, and fetch it if not nameless - if (get_rawinput_device_info(rawinputdevice->hDevice, RIDI_DEVICENAME, nullptr, &name_length) != 0) + if ((*get_rawinput_device_info)(rawinputdevice->hDevice, RIDI_DEVICENAME, nullptr, &name_length) != 0) return nullptr; std::unique_ptr<TCHAR[]> tname = std::make_unique<TCHAR[]>(name_length + 1); - if (name_length > 1 && get_rawinput_device_info(rawinputdevice->hDevice, RIDI_DEVICENAME, tname.get(), &name_length) == -1) + if (name_length > 1 && (*get_rawinput_device_info)(rawinputdevice->hDevice, RIDI_DEVICENAME, tname.get(), &name_length) == -1) return nullptr; // if this is an RDP name, skip it @@ -544,14 +530,14 @@ protected: std::unique_ptr<BYTE[]> larger_buffer; LPBYTE data = small_buffer; BOOL result; - int size; + UINT size; // ignore if not enabled if (!input_enabled()) return FALSE; // determine the size of databuffer we need - if (get_rawinput_data(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0) + if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0) return FALSE; // if necessary, allocate a temporary buffer and fetch the data @@ -564,7 +550,7 @@ protected: } // fetch the data and process the appropriate message types - result = get_rawinput_data(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); + result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); if (result) { std::lock_guard<std::mutex> scope_lock(m_module_lock); |