mirror of
https://github.com/PCSX2/pcsx2.git
synced 2026-07-11 01:34:17 +02:00
Misc: another COM code cleanup
This commit is contained in:
@@ -376,9 +376,11 @@ bool TAPGetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSES adapter,
|
||||
HRESULT cohr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (cohr == RPC_E_CHANGED_MODE)
|
||||
cohr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
if (!SUCCEEDED(cohr))
|
||||
if (FAILED(cohr))
|
||||
return false;
|
||||
|
||||
wil::unique_couninitialize_call uninit;
|
||||
|
||||
PIP_ADAPTER_ADDRESSES bridgeAdapter = nullptr;
|
||||
|
||||
//Create Instance of INetCfg
|
||||
@@ -472,8 +474,6 @@ bool TAPGetWin32Adapter(const std::string& name, PIP_ADAPTER_ADDRESSES adapter,
|
||||
}
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
if (bridgeAdapter != nullptr)
|
||||
{
|
||||
*adapter = *bridgeAdapter;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "USB/USB.h"
|
||||
|
||||
#include <jpeglib.h>
|
||||
#include <wil/com.h>
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
@@ -57,16 +58,15 @@ namespace usb_eyetoy
|
||||
{
|
||||
std::vector<std::pair<std::string, std::string>> devList;
|
||||
|
||||
ICreateDevEnum* pCreateDevEnum = nullptr;
|
||||
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCreateDevEnum));
|
||||
if (FAILED(hr))
|
||||
wil::com_ptr_nothrow<ICreateDevEnum> pCreateDevEnum = wil::CoCreateInstanceNoThrow<ICreateDevEnum>(CLSID_SystemDeviceEnum);
|
||||
if (!pCreateDevEnum)
|
||||
{
|
||||
Console.Warning("Camera: Error Creating Device Enumerator");
|
||||
return devList;
|
||||
}
|
||||
|
||||
wil::com_ptr_nothrow<IEnumMoniker> pEnum;
|
||||
hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);
|
||||
HRESULT hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0);
|
||||
if (hr != S_OK)
|
||||
{
|
||||
Console.Warning("Camera: You have no video capture hardware");
|
||||
@@ -97,8 +97,6 @@ namespace usb_eyetoy
|
||||
}
|
||||
}
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
return devList;
|
||||
}
|
||||
|
||||
@@ -136,9 +134,8 @@ namespace usb_eyetoy
|
||||
}
|
||||
|
||||
// enumerate all video capture devices
|
||||
ICreateDevEnum* pCreateDevEnum = nullptr;
|
||||
hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pCreateDevEnum));
|
||||
if (FAILED(hr))
|
||||
wil::com_ptr_nothrow<ICreateDevEnum> pCreateDevEnum = wil::CoCreateInstanceNoThrow<ICreateDevEnum>(CLSID_SystemDeviceEnum);
|
||||
if (!pCreateDevEnum)
|
||||
{
|
||||
Console.Warning("Camera: Error Creating Device Enumerator");
|
||||
return -1;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "common/FileSystem.h"
|
||||
#include "common/Console.h"
|
||||
#include "common/ScopedGuard.h"
|
||||
#include "common/StringUtil.h"
|
||||
#include "common/ProgressCallback.h"
|
||||
#include "common/RedtapeWilCom.h"
|
||||
@@ -18,6 +17,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include <wil/resource.h>
|
||||
#include <wil/result.h>
|
||||
#include <wil/win32_helpers.h>
|
||||
|
||||
#pragma comment(lib, "synchronization.lib")
|
||||
@@ -76,7 +76,7 @@ private:
|
||||
wil::com_ptr_nothrow<ITaskbarList3> m_taskbar_list;
|
||||
|
||||
int m_last_progress_percent = -1;
|
||||
bool m_com_initialized = false;
|
||||
wil::unique_couninitialize_call m_com_initialized{false};
|
||||
|
||||
static inline const UINT s_uTBBC = RegisterWindowMessageW(L"TaskbarButtonCreated");
|
||||
static constexpr UINT WMAPP_SETTASKBARPROGRESS = WM_USER+0;
|
||||
@@ -192,7 +192,7 @@ bool Win32ProgressCallback::Create()
|
||||
class_registered = true;
|
||||
}
|
||||
|
||||
m_com_initialized = SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED));
|
||||
m_com_initialized = wil::CoInitializeEx_failfast(COINIT_APARTMENTTHREADED);
|
||||
|
||||
m_window_hwnd =
|
||||
CreateWindowExW(WS_EX_CLIENTEDGE, CLASS_NAME, L"Win32ProgressCallback", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, CW_USEDEFAULT,
|
||||
@@ -222,8 +222,7 @@ void Win32ProgressCallback::Destroy()
|
||||
m_progress_hwnd = {};
|
||||
}
|
||||
|
||||
if (m_com_initialized)
|
||||
CoUninitialize();
|
||||
m_com_initialized.reset();
|
||||
}
|
||||
|
||||
void Win32ProgressCallback::PumpMessages()
|
||||
@@ -420,11 +419,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
||||
{
|
||||
Win32ProgressCallback progress;
|
||||
|
||||
const bool com_initialized = SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED));
|
||||
const ScopedGuard com_guard = [com_initialized]() {
|
||||
if (com_initialized)
|
||||
CoUninitialize();
|
||||
};
|
||||
wil::unique_couninitialize_call uninit = wil::CoInitializeEx_failfast(COINIT_MULTITHREADED);
|
||||
|
||||
int argc = 0;
|
||||
wil::unique_hlocal_ptr<LPWSTR[]> argv(CommandLineToArgvW(GetCommandLineW(), &argc));
|
||||
|
||||
Reference in New Issue
Block a user