-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDinputTester.cpp
More file actions
57 lines (48 loc) · 1.5 KB
/
DinputTester.cpp
File metadata and controls
57 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <chrono>
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#pragma comment(lib, "dinput8")
#pragma comment(lib, "dxguid")
using perf_clock = std::chrono::high_resolution_clock;
static perf_clock::time_point last_time;
BOOL CALLBACK EnumDevicesCb(LPCDIDEVICEINSTANCE diDevice, LPVOID)
{
wchar_t guid[40];
if (StringFromGUID2(diDevice->guidProduct, guid, ARRAYSIZE(guid)))
{
auto now = perf_clock::now();
auto duration_ms = std::chrono::duration<double, std::milli>(now - last_time);
last_time = now;
std::wcout
<< L"Name: " << diDevice->tszProductName << L"\n"
<< L"GUID: " << guid << L"\n"
<< L"Enum time: " << duration_ms.count() << L" ms\n\n";
}
else {
std::wcerr << L"Could not extract GUID for " << diDevice->tszProductName << L"\n";
}
return DIENUM_CONTINUE;
}
int main()
{
IDirectInput8* di8;
HRESULT hr = DirectInput8Create(GetModuleHandleW(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&di8, nullptr);
if (FAILED(hr))
{
std::cerr << "Could not create DirectInput 8 handle\n";
return 1;
}
last_time = perf_clock::now();
if (di8->EnumDevices(DI8DEVCLASS_ALL, EnumDevicesCb, nullptr, DIEDFL_ATTACHEDONLY) != DI_OK)
{
std::cerr << "Could not enumerate devices.\n";
return 2;
}
di8->Release();
di8 = nullptr;
return 0;
}