Use HRWrap in remaining locations

Note that D3DCommon can't use DX11HRWrap or DX12HRWrap since it's shared between them.
This commit is contained in:
Pokechu22
2021-12-12 13:50:18 -08:00
parent 1b32e6dae2
commit ca9bf3174f
8 changed files with 58 additions and 34 deletions

View File

@ -3,6 +3,7 @@
#include "InputCommon/ControllerInterface/DInput/DInput.h"
#include "Common/HRWrap.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
@ -37,13 +38,15 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
str.diph.dwHow = DIPH_DEVICE;
std::string result;
if (SUCCEEDED(device->GetProperty(DIPROP_PRODUCTNAME, &str.diph)))
HRESULT hr = device->GetProperty(DIPROP_PRODUCTNAME, &str.diph);
if (SUCCEEDED(hr))
{
result = StripSpaces(WStringToUTF8(str.wsz));
}
else
{
ERROR_LOG_FMT(CONTROLLERINTERFACE, "GetProperty(DIPROP_PRODUCTNAME) failed.");
ERROR_LOG_FMT(CONTROLLERINTERFACE, "GetProperty(DIPROP_PRODUCTNAME) failed: {}",
Common::HRWrap(hr));
}
return result;
@ -52,11 +55,15 @@ std::string GetDeviceName(const LPDIRECTINPUTDEVICE8 device)
// Assumes hwnd had not changed from the previous call
void PopulateDevices(HWND hwnd)
{
if (!s_idi8 && FAILED(DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION,
IID_IDirectInput8, (LPVOID*)&s_idi8, nullptr)))
if (!s_idi8)
{
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DirectInput8Create failed.");
return;
HRESULT hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION,
IID_IDirectInput8, (LPVOID*)&s_idi8, nullptr);
if (FAILED(hr))
{
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DirectInput8Create failed: {}", Common::HRWrap(hr));
return;
}
}
// Remove old (invalid) devices. No need to ever remove the KeyboardMouse device.

View File

@ -10,6 +10,7 @@
#include <sstream>
#include <type_traits>
#include "Common/HRWrap.h"
#include "Common/Logging/Log.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
@ -62,12 +63,14 @@ void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
{
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
{
if (FAILED(js_device->SetCooperativeLevel(GetAncestor(hwnd, GA_ROOT),
DISCL_BACKGROUND | DISCL_EXCLUSIVE)))
HRESULT hr = js_device->SetCooperativeLevel(GetAncestor(hwnd, GA_ROOT),
DISCL_BACKGROUND | DISCL_EXCLUSIVE);
if (FAILED(hr))
{
WARN_LOG_FMT(
CONTROLLERINTERFACE,
"DInput: Failed to acquire device exclusively. Force feedback will be unavailable.");
WARN_LOG_FMT(CONTROLLERINTERFACE,
"DInput: Failed to acquire device exclusively. Force feedback will be "
"unavailable. {}",
Common::HRWrap(hr));
// Fall back to non-exclusive mode, with no rumble
if (FAILED(
js_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))

View File

@ -11,6 +11,7 @@
#include <thread>
#include "Common/Flag.h"
#include "Common/HRWrap.h"
#include "Common/Logging/Log.h"
#include "Common/ScopeGuard.h"
#include "Common/Thread.h"
@ -61,9 +62,10 @@ void ciface::Win32::Init(void* hwnd)
HWND message_window = nullptr;
Common::ScopeGuard promise_guard([&] { message_window_promise.set_value(message_window); });
if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
ERROR_LOG_FMT(CONTROLLERINTERFACE, "CoInitializeEx failed: {}", GetLastError());
ERROR_LOG_FMT(CONTROLLERINTERFACE, "CoInitializeEx failed: {}", Common::HRWrap(hr));
return;
}
Common::ScopeGuard uninit([] { CoUninitialize(); });
@ -77,12 +79,14 @@ void ciface::Win32::Init(void* hwnd)
ATOM window_class = RegisterClassEx(&window_class_info);
if (!window_class)
{
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "RegisterClassEx failed: {}", GetLastError());
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "RegisterClassEx failed: {}",
Common::HRWrap(GetLastError()));
return;
}
Common::ScopeGuard unregister([&window_class] {
if (!UnregisterClass(MAKEINTATOM(window_class), GetModuleHandle(nullptr)))
ERROR_LOG_FMT(CONTROLLERINTERFACE, "UnregisterClass failed: {}", GetLastError());
ERROR_LOG_FMT(CONTROLLERINTERFACE, "UnregisterClass failed: {}",
Common::HRWrap(GetLastError()));
});
message_window = CreateWindowEx(0, L"Message", nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr,
@ -90,12 +94,14 @@ void ciface::Win32::Init(void* hwnd)
promise_guard.Exit();
if (!message_window)
{
ERROR_LOG_FMT(CONTROLLERINTERFACE, "CreateWindowEx failed: {}", GetLastError());
ERROR_LOG_FMT(CONTROLLERINTERFACE, "CreateWindowEx failed: {}",
Common::HRWrap(GetLastError()));
return;
}
Common::ScopeGuard destroy([&] {
if (!DestroyWindow(message_window))
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DestroyWindow failed: {}", GetLastError());
ERROR_LOG_FMT(CONTROLLERINTERFACE, "DestroyWindow failed: {}",
Common::HRWrap(GetLastError()));
});
std::array<RAWINPUTDEVICE, 2> devices;