TDevice* create_rawinput_device(running_machine &machine, PRAWINPUTDEVICELIST rawinputdevice) { 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) 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) return nullptr; // if this is an RDP name, skip it if (_tcsstr(tname.get(), TEXT("Root#RDP_")) != NULL) return nullptr; // improve the name and then allocate a device tname = std::unique_ptr<TCHAR[]>(rawinput_device_improve_name(tname.release())); // convert name to utf8 auto osd_deleter = [](void *ptr) { osd_free(ptr); }; auto utf8_name = std::unique_ptr<char, decltype(osd_deleter)>(utf8_from_tstring(tname.get()), osd_deleter); devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.get(), *this); // Add the handle devinfo->set_handle(rawinputdevice->hDevice); return devinfo; }
TDevice* create_rawinput_device(running_machine &machine, PRAWINPUTDEVICELIST rawinputdevice) { TDevice* devinfo; 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) 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) return nullptr; // if this is an RDP name, skip it if (_tcsstr(tname.get(), TEXT("Root#RDP_")) != nullptr) return nullptr; // improve the name and then allocate a device std::wstring name = rawinput_device_improve_name(tname.get()); // convert name to utf8 std::string utf8_name = osd::text::from_wstring(name.c_str()); // set device id to raw input name std::string utf8_id = osd::text::from_wstring(tname.get()); devinfo = devicelist()->create_device<TDevice>(machine, utf8_name.c_str(), utf8_id.c_str(), *this); // Add the handle devinfo->set_handle(rawinputdevice->hDevice); return devinfo; }