I'm trying to enumerate Joysticks in DirectInput.
unsigned int GetCount()
{
unsigned int counter;
LPDIRECTINPUT8 di;
HRESULT hr;
counter = 0;
di = NULL;
if (SUCCEEDED(hr = DirectInput8Create(GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(VOID**)&di, NULL)))
{
di->EnumDevices(DI8DEVCLASS_GAMECTRL, countCallback, &counter, DIEDFL_ATTACHEDONLY);
}
return counter;
}
FYI - This is in a c file using the C compiler.
I'm getting these curious errors.
error C2039: 'EnumDevices' : is not a member of 'IDirectInput8A'
error C2440: 'function' : cannot convert from 'const GUID' to 'const IID *const '
The first one is referring to the line that begins di->EnumDevices...
The second is referring to IID_IDirectInput8
in DirectInput8Create
.
I've played around with the UNICODE settings to see if it matters. Nope.
This feels like something very basic.
I solved it myself.
Since it is C and not C++, we need to declare all of this at the top:
#define CINTERFACE
#define INITGUID
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#pragma comment (lib, "dinput8.lib")
This in the DirectInput8Create:
&IID_IDirectInput8,
This in the Enum line:
di->lpVtbl->EnumDevices(di, DI8DEVCLASS_GAMECTRL, deviceCountCallback, &count, DIEDFL_ATTACHEDONLY);