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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
// For licensing and usage information, read docs/winui_license.txt
// MASTER
//****************************************************************************
/***************************************************************************
directinput.cpp
Direct Input routines.
***************************************************************************/
// standard windows headers
#include <windows.h>
// MAME/MAMEUI headers
#include "mui_util.h" // For ErrorMsg
#include "directinput.h"
/***************************************************************************
function prototypes
***************************************************************************/
/***************************************************************************
External variables
***************************************************************************/
/***************************************************************************
Internal structures
***************************************************************************/
/***************************************************************************
Internal variables
***************************************************************************/
static LPDIRECTINPUT di = NULL;
static HANDLE hDLL = NULL;
/***************************************************************************
External functions
***************************************************************************/
/****************************************************************************
* DirectInputInitialize
*
* Initialize the DirectInput variables.
*
* This entails the following functions:
*
* DirectInputCreate
*
****************************************************************************/
typedef HRESULT (WINAPI *dic_proc)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT *ppDI, LPUNKNOWN punkOuter);
BOOL DirectInputInitialize()
{
if (hDLL)
return TRUE;
/* Turn off error dialog for this call */
UINT error_mode = SetErrorMode(0);
hDLL = LoadLibrary(TEXT("dinput.dll"));
SetErrorMode(error_mode);
if (hDLL == NULL)
return FALSE;
dic_proc dic;
#ifdef UNICODE
dic = (dic_proc)GetProcAddress((HINSTANCE)hDLL, "DirectInputCreateW");
#else
dic = (dic_proc)GetProcAddress((HINSTANCE)hDLL, "DirectInputCreateA");
#endif
if (dic == NULL)
return false;
HRESULT hr = dic(GetModuleHandle(NULL), 0x0700, &di, NULL); // setup DIRECT INPUT 7 for the GUI
if (FAILED(hr))
{
hr = dic(GetModuleHandle(NULL), 0x0500, &di, NULL); // if failed, try with version 5
if (FAILED(hr))
{
ErrorMsg("DirectInputCreate failed! error=%x\n", (unsigned int)hr);
di = NULL;
return false;
}
}
return true;
}
/****************************************************************************
*
* DirectInputClose
*
* Terminate our usage of DirectInput.
*
****************************************************************************/
void DirectInputClose()
{
/* Release any lingering IDirectInput object. */
if (di)
{
IDirectInput_Release(di);
di = NULL;
}
}
BOOL CALLBACK inputEnumDeviceProc(LPCDIDEVICEINSTANCE pdidi, LPVOID pv)
{
GUID *pguidDevice;
/* report back the instance guid of the device we enumerated */
if (pv)
{
pguidDevice = (GUID *)pv;
*pguidDevice = pdidi->guidInstance;
}
/* BUGBUG for now, stop after the first device has been found */
return DIENUM_STOP;
}
HRESULT SetDIDwordProperty(LPDIRECTINPUTDEVICE2 pdev, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, DWORD dwValue)
{
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(dipdw);
dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
dipdw.diph.dwObj = dwObject;
dipdw.diph.dwHow = dwHow;
dipdw.dwData = dwValue;
return IDirectInputDevice2_SetProperty(pdev, guidProperty, &dipdw.diph);
}
LPDIRECTINPUT GetDirectInput(void)
{
return di;
}
|