From 028b4c5b216073566fc9660f7e21bf9a8e9c5e40 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Wed, 2 Mar 2016 16:23:45 -0500 Subject: Fix DirectWrite font module init error handling --- src/osd/windows/winutil.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/osd/windows/winutil.cpp') diff --git a/src/osd/windows/winutil.cpp b/src/osd/windows/winutil.cpp index fe835301907..05dd1541ced 100644 --- a/src/osd/windows/winutil.cpp +++ b/src/osd/windows/winutil.cpp @@ -187,14 +187,20 @@ int lazy_loaded_function::initialize() } if (m_module == NULL) + { + osd_printf_verbose("Could not find DLL to dynamically link function %s.\n", m_name.c_str()); return ERROR_DLL_NOT_FOUND; + } } if (m_pfn == nullptr) { m_pfn = GetProcAddress(m_module, m_name.c_str()); if (m_pfn == nullptr) + { + osd_printf_verbose("Could not find function address to dynamically link function %s.\n", m_name.c_str()); return ERROR_NOT_FOUND; + } } m_initialized = true; -- cgit v1.2.3-70-g09d2 From e153edfaec8a556b1d831df7134f65102f4e5b37 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Thu, 3 Mar 2016 11:26:08 -0500 Subject: Code cleanup in rawinput plus use common code for dynamic function binding. --- src/osd/modules/input/input_rawinput.cpp | 96 ++++++++++++++------------------ src/osd/windows/winutil.cpp | 2 +- src/osd/windows/winutil.h | 22 ++++++++ 3 files changed, 64 insertions(+), 56 deletions(-) (limited to 'src/osd/windows/winutil.cpp') diff --git a/src/osd/modules/input/input_rawinput.cpp b/src/osd/modules/input/input_rawinput.cpp index 5f930e5d780..84d8a96fec3 100644 --- a/src/osd/modules/input/input_rawinput.cpp +++ b/src/osd/modules/input/input_rawinput.cpp @@ -27,6 +27,7 @@ #include "strconv.h" // MAMEOS headers +#include "winutil.h" #include "winmain.h" #include "window.h" @@ -44,10 +45,10 @@ #endif // RawInput APIs -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_device_list_ptr)(OUT PRAWINPUTDEVICELIST pRawInputDeviceList, IN OUT PINT puiNumDevices, IN UINT cbSize); -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_data_ptr)(IN HRAWINPUT hRawInput, IN UINT uiCommand, OUT LPVOID pData, IN OUT PINT pcbSize, IN UINT cbSizeHeader); -typedef /*WINUSERAPI*/ INT(WINAPI *get_rawinput_device_info_ptr)(IN HANDLE hDevice, IN UINT uiCommand, OUT LPVOID pData, IN OUT PINT pcbSize); -typedef /*WINUSERAPI*/ BOOL(WINAPI *register_rawinput_devices_ptr)(IN PCRAWINPUTDEVICE pRawInputDevices, IN UINT uiNumDevices, IN UINT cbSize); +typedef lazy_loaded_function_p3 get_rawinput_device_list_ptr; +typedef lazy_loaded_function_p5 get_rawinput_data_ptr; +typedef lazy_loaded_function_p4 get_rawinput_device_info_ptr; +typedef lazy_loaded_function_p3 register_rawinput_devices_ptr; //============================================================ // reg_query_string @@ -289,19 +290,11 @@ public: // rawinput_mouse_device //============================================================ -struct rawinput_mouse_state -{ - int raw_x; - int raw_y; - int raw_z; -}; - class rawinput_mouse_device : public rawinput_device { private: std::mutex m_device_lock; public: - //rawinput_mouse_state raw_mouse; mouse_state mouse; rawinput_mouse_device(running_machine& machine, const char* name, input_module& module) @@ -317,18 +310,6 @@ public: mouse.lZ = 0; rawinput_device::poll(); - - //std::lock_guard scope_lock(m_device_lock); - - //// copy the accumulated raw state to the actual state - //mouse.lX = raw_mouse.raw_x; - //mouse.lY = raw_mouse.raw_y; - //mouse.lZ = raw_mouse.raw_z; - //raw_mouse.raw_x = 0; - //raw_mouse.raw_y = 0; - //raw_mouse.raw_z = 0; - - //osd_printf_verbose("At poll: lX=%d, lY=%d, lZ=%d\n", (int)mouse.lX, (int)mouse.lY, (int)mouse.lZ); } void reset() override @@ -345,13 +326,6 @@ public: mouse.lX += rawinput.data.mouse.lLastX * INPUT_RELATIVE_PER_PIXEL; mouse.lY += rawinput.data.mouse.lLastY * INPUT_RELATIVE_PER_PIXEL; - /*osd_printf_verbose( - "Mouse Abs : lastX = %d, lastY = %d, rawx = %d, rawy = %d\n", - (int)rawinput.data.mouse.lLastX, - (int)rawinput.data.mouse.lLastY, - (int)raw_mouse.raw_x, - (int)raw_mouse.raw_y);*/ - // update zaxis if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) mouse.lZ += (INT16)rawinput.data.mouse.usButtonData * INPUT_RELATIVE_PER_PIXEL; @@ -370,6 +344,13 @@ 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 //============================================================ @@ -387,25 +368,38 @@ private: public: rawinput_module(const char *type, const char* name) : wininput_module(type, name), - get_rawinput_device_list(nullptr), - get_rawinput_data(nullptr), - get_rawinput_device_info(nullptr), - register_rawinput_devices(nullptr) + 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") { } + 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(); + + if (status != 0) + return false; + + return true; + } + 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)(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) + if (get_rawinput_device_list(NULL, &device_count, sizeof(RAWINPUTDEVICELIST)) != 0) return; if (device_count == 0) return; auto rawinput_devices = std::make_unique(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 @@ -433,7 +427,7 @@ public: registration.hwndTarget = win_window_list->m_hwnd; // register the device - (*register_rawinput_devices)(®istration, 1, sizeof(registration)); + register_rawinput_devices(®istration, 1, sizeof(registration)); } protected: @@ -443,23 +437,15 @@ protected: int init_internal() override { - HMODULE user32; - - // look in user32 for the raw input APIs - user32 = LoadLibrary(TEXT("user32.dll")); - if (user32 == NULL) - return 1; - // look up the entry points - 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"); - if (register_rawinput_devices == NULL || get_rawinput_device_list == NULL || get_rawinput_device_info == NULL || get_rawinput_data == NULL) + 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) return 1; osd_printf_verbose("RawInput: APIs detected\n"); - return 0; } @@ -469,11 +455,11 @@ protected: TDevice* devinfo = nullptr; INT 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, NULL, &name_length) != 0) + if (get_rawinput_device_info(rawinputdevice->hDevice, RIDI_DEVICENAME, NULL, &name_length) != 0) return nullptr; std::unique_ptr tname = std::make_unique(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 @@ -514,7 +500,7 @@ protected: return FALSE; // determine the size of databuffer we need - if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) != 0) + if (get_rawinput_data(rawinputdevice, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)) != 0) return FALSE; // if necessary, allocate a temporary buffer and fetch the data @@ -527,7 +513,7 @@ protected: } // fetch the data and process the appropriate message types - result = (*get_rawinput_data)((HRAWINPUT)rawinputdevice, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); + result = get_rawinput_data((HRAWINPUT)rawinputdevice, RID_INPUT, data, &size, sizeof(RAWINPUTHEADER)); if (result) { std::lock_guard scope_lock(m_module_lock); diff --git a/src/osd/windows/winutil.cpp b/src/osd/windows/winutil.cpp index 05dd1541ced..eb63eecacd0 100644 --- a/src/osd/windows/winutil.cpp +++ b/src/osd/windows/winutil.cpp @@ -160,7 +160,7 @@ lazy_loaded_function::lazy_loaded_function(const char * name, const wchar_t* dll } lazy_loaded_function::lazy_loaded_function(const char * name, const wchar_t** dll_names, int dll_count) - : m_name(name), m_initialized(false), m_pfn(nullptr) + : m_name(name), m_module(NULL), m_initialized(false), m_pfn(nullptr) { for (int i = 0; i < dll_count; i++) m_dll_names.push_back(std::wstring(dll_names[i])); diff --git a/src/osd/windows/winutil.h b/src/osd/windows/winutil.h index 8f205e5a8ba..530327dcf61 100644 --- a/src/osd/windows/winutil.h +++ b/src/osd/windows/winutil.h @@ -153,4 +153,26 @@ public: } }; +// Five parameters +template +class lazy_loaded_function_p5 : public lazy_loaded_function +{ +public: + lazy_loaded_function_p5(const char * name, const wchar_t* dll_name) + : lazy_loaded_function(name, &dll_name, 1) + { + } + + lazy_loaded_function_p5(const char * name, const wchar_t** dll_names, int dll_count) + : lazy_loaded_function(name, dll_names, dll_count) + { + } + + TRet operator ()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) + { + check_init(); + return ((TRet(__stdcall *) (P1, P2, P3, P4, P5))m_pfn)(p1, p2, p3, p4, p5); + } +}; + #endif // __WINUTIL__ -- cgit v1.2.3-70-g09d2