Refactor to use Microsoft::WRL::ComPtr (#1599)

This commit is contained in:
oltolm 2025-06-16 23:25:06 +02:00 committed by GitHub
parent da98aa4176
commit 2f02fda9ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 56 additions and 119 deletions

View file

@ -15,9 +15,6 @@ DirectInputController::DirectInputController(const GUID& guid, std::string_view
DirectInputController::~DirectInputController()
{
if (m_effect)
m_effect->Release();
if (m_device)
{
m_device->Unacquire();
@ -39,8 +36,8 @@ DirectInputController::~DirectInputController()
if (kGameCubeController == m_product_guid)
should_release_device = false;
if (should_release_device)
m_device->Release();
if (!should_release_device)
m_device.Detach();
}
}
@ -104,7 +101,6 @@ bool DirectInputController::connect()
// set data format
if (FAILED(m_device->SetDataFormat(m_provider->get_data_format())))
{
SAFE_RELEASE(m_device);
return false;
}
@ -115,7 +111,6 @@ bool DirectInputController::connect()
{
if (FAILED(m_device->SetCooperativeLevel(hwndMainWindow, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
SAFE_RELEASE(m_device);
return false;
}
// rumble can only be used with exclusive access

View file

@ -2,6 +2,7 @@
#include "input/api/DirectInput/DirectInputControllerProvider.h"
#include "input/api/Controller.h"
#include <wrl/client.h>
class DirectInputController : public Controller<DirectInputControllerProvider>
{
@ -41,9 +42,9 @@ private:
GUID m_product_guid{};
std::shared_mutex m_mutex;
LPDIRECTINPUTDEVICE8 m_device = nullptr;
LPDIRECTINPUTEFFECT m_effect = nullptr;
Microsoft::WRL::ComPtr<IDirectInputDevice8> m_device;
Microsoft::WRL::ComPtr<IDirectInputEffect> m_effect;
std::array<LONG, 6> m_min_axis{};
std::array<LONG, 6> m_max_axis{};
};
};

View file

@ -19,7 +19,7 @@ DirectInputControllerProvider::DirectInputControllerProvider()
const auto r = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_dinput8, nullptr);
if (FAILED(r) || !m_dinput8)
if (FAILED(r))
{
const auto error = GetLastError();
//FreeLibrary(m_module);
@ -29,9 +29,6 @@ DirectInputControllerProvider::DirectInputControllerProvider()
DirectInputControllerProvider::~DirectInputControllerProvider()
{
if (m_dinput8)
m_dinput8->Release();
/*if (m_module)
FreeLibrary(m_module);
*/

View file

@ -4,6 +4,7 @@
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include <wrl/client.h>
#include "input/api/ControllerProvider.h"
@ -22,7 +23,7 @@ public:
std::vector<std::shared_ptr<ControllerBase>> get_controllers() override;
IDirectInput8* get_dinput() const { return m_dinput8; }
IDirectInput8* get_dinput() const { return m_dinput8.Get(); }
LPCDIDATAFORMAT get_data_format() const;
private:
@ -31,7 +32,7 @@ private:
decltype(&DirectInput8Create) m_DirectInput8Create;
decltype(&GetdfDIJoystick) m_GetdfDIJoystick = nullptr;
IDirectInput8* m_dinput8 = nullptr;
Microsoft::WRL::ComPtr<IDirectInput8> m_dinput8;
};
#endif
#endif