-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain2.cpp
More file actions
executable file
·104 lines (82 loc) · 2.66 KB
/
main2.cpp
File metadata and controls
executable file
·104 lines (82 loc) · 2.66 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
using namespace std;
LPDIRECTINPUT8 di;
LPDIRECTINPUTDEVICE8 pad;
BOOL CALLBACK CreateDeviceCallback(
LPCDIDEVICEINSTANCE instance,
LPVOID reference)
{
HRESULT result;
// Création du périphérique
result = di_object->CreateDevice( instance->guidInstance, &xpad, NULL);
// Gestion des erreurs
if(FAILED( result ))
return DIENUM_CONTINUE;
// En cas de réussite ... on arrête l'enumération
return DIENUM_STOP;
}
int main()
{
// ==== Création de l'instance DI
HRESULT result;
HINSTANCE hinst = (HINSTANCE)GetModuleHandle(NULL);
result = DirectInput8Create(hinst,
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void **)&di_object,
NULL);
if (FAILED(result))
{
cout << "Error in DI Instance summoning." << endl;
return 1;
}
// ==== Connexion avec le premier PAD trouvé
result = di_object->EnumDevices(DI8DEVCLASS_GAMECTRL,
&CreateDeviceCallback,
NULL,
DIEDFL_ATTACHEDONLY);
// ==== Communication avec le PAD
result=xpad->SetDataFormat(&c_dfDIJoystick2);
if(FAILED(result))
{
cout << "Problème config du format";
return 3;
}
// ==== Récupération des états du PAD
DIJOYSTATE2 state;
if(FAILED(result))
{
cout << "Impossible de récupérer l'etat du périphérique.";
return 5;
}
xpad->Acquire();
DIDEVICEINSTANCE device;
ZeroMemory(&device, sizeof(device));
device.dwSize = sizeof(device);
xpad->GetDeviceInfo(&device);
while(1)
{
result = xpad->GetDeviceState(
sizeof(state),
(LPVOID)&state);
if(FAILED(result))
{
cout << "Impossible de récupérer l'etat du périphérique.";
return 5;
}
if(state.rgbButtons[0])
break;
cout << "X : " << state.lX << endl;
cout << "Y : " << state.lY << endl;
cout << "DEVICE : " << device.tszProductName;
Sleep(100);
system("CLS");
}
xpad->Unacquire();
xpad->Release();
di_object->Release();
cout << "Programme fini.";
return 0;
}