fix(audio-info): crash when device name contains special characters (#4095)
This commit is contained in:
parent
fd2bfaac7e
commit
ab52e27e0e
14 changed files with 476 additions and 163 deletions
|
|
@ -3,10 +3,12 @@
|
|||
* @brief Displays information about connected displays and GPUs
|
||||
*/
|
||||
#define WINVER 0x0A00
|
||||
#include "src/platform/windows/utf_utils.h"
|
||||
#include "src/utility.h"
|
||||
|
||||
#include <d3dcommon.h>
|
||||
#include <dxgi.h>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std::literals;
|
||||
|
|
@ -20,17 +22,14 @@ namespace dxgi {
|
|||
using factory1_t = util::safe_ptr<IDXGIFactory1, Release<IDXGIFactory1>>;
|
||||
using adapter_t = util::safe_ptr<IDXGIAdapter1, Release<IDXGIAdapter1>>;
|
||||
using output_t = util::safe_ptr<IDXGIOutput, Release<IDXGIOutput>>;
|
||||
|
||||
} // namespace dxgi
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
HRESULT status;
|
||||
|
||||
// Set ourselves as per-monitor DPI aware for accurate resolution values on High DPI systems
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
|
||||
dxgi::factory1_t::pointer factory_p {};
|
||||
status = CreateDXGIFactory1(IID_IDXGIFactory1, (void **) &factory_p);
|
||||
const HRESULT status = CreateDXGIFactory1(IID_IDXGIFactory1, static_cast<void **>(static_cast<void *>(&factory_p)));
|
||||
dxgi::factory1_t factory {factory_p};
|
||||
if (FAILED(status)) {
|
||||
std::cout << "Failed to create DXGIFactory1 [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||
|
|
@ -44,21 +43,24 @@ int main(int argc, char *argv[]) {
|
|||
DXGI_ADAPTER_DESC1 adapter_desc;
|
||||
adapter->GetDesc1(&adapter_desc);
|
||||
|
||||
std::cout
|
||||
<< "====== ADAPTER ====="sv << std::endl;
|
||||
std::wcout
|
||||
<< L"Device Name : "sv << adapter_desc.Description << std::endl;
|
||||
std::cout
|
||||
<< "Device Vendor ID : 0x"sv << util::hex(adapter_desc.VendorId).to_string_view() << std::endl
|
||||
<< "Device Device ID : 0x"sv << util::hex(adapter_desc.DeviceId).to_string_view() << std::endl
|
||||
<< "Device Video Mem : "sv << adapter_desc.DedicatedVideoMemory / 1048576 << " MiB"sv << std::endl
|
||||
<< "Device Sys Mem : "sv << adapter_desc.DedicatedSystemMemory / 1048576 << " MiB"sv << std::endl
|
||||
<< "Share Sys Mem : "sv << adapter_desc.SharedSystemMemory / 1048576 << " MiB"sv << std::endl
|
||||
<< std::endl
|
||||
<< " ====== OUTPUT ======"sv << std::endl;
|
||||
std::cout << "====== ADAPTER =====" << std::endl;
|
||||
std::cout << "Device Name : " << utf_utils::to_utf8(std::wstring(adapter_desc.Description)) << std::endl;
|
||||
std::cout << "Device Vendor ID : " << "0x" << util::hex(adapter_desc.VendorId).to_string() << std::endl;
|
||||
std::cout << "Device Device ID : " << "0x" << util::hex(adapter_desc.DeviceId).to_string() << std::endl;
|
||||
std::cout << "Device Video Mem : " << std::format("{} MiB", adapter_desc.DedicatedVideoMemory / 1048576) << std::endl;
|
||||
std::cout << "Device Sys Mem : " << std::format("{} MiB", adapter_desc.DedicatedSystemMemory / 1048576) << std::endl;
|
||||
std::cout << "Share Sys Mem : " << std::format("{} MiB", adapter_desc.SharedSystemMemory / 1048576) << std::endl;
|
||||
|
||||
dxgi::output_t::pointer output_p {};
|
||||
bool has_outputs = false;
|
||||
for (int y = 0; adapter->EnumOutputs(y, &output_p) != DXGI_ERROR_NOT_FOUND; ++y) {
|
||||
// Print the header only when we find the first output
|
||||
if (!has_outputs) {
|
||||
std::cout << std::endl
|
||||
<< " ====== OUTPUT ======" << std::endl;
|
||||
has_outputs = true;
|
||||
}
|
||||
|
||||
dxgi::output_t output {output_p};
|
||||
|
||||
DXGI_OUTPUT_DESC desc;
|
||||
|
|
@ -67,13 +69,11 @@ int main(int argc, char *argv[]) {
|
|||
auto width = desc.DesktopCoordinates.right - desc.DesktopCoordinates.left;
|
||||
auto height = desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top;
|
||||
|
||||
std::wcout
|
||||
<< L" Output Name : "sv << desc.DeviceName << std::endl;
|
||||
std::cout
|
||||
<< " AttachedToDesktop : "sv << (desc.AttachedToDesktop ? "yes"sv : "no"sv) << std::endl
|
||||
<< " Resolution : "sv << width << 'x' << height << std::endl
|
||||
<< std::endl;
|
||||
std::cout << " Output Name : " << utf_utils::to_utf8(std::wstring(desc.DeviceName)) << std::endl;
|
||||
std::cout << " AttachedToDesktop : " << (desc.AttachedToDesktop ? "yes" : "no") << std::endl;
|
||||
std::cout << " Resolution : " << std::format("{}x{}", width, height) << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue