0

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.

101010
  • 14,866
  • 30
  • 95
  • 172
  • You may want to see the [DirectInput samples](https://code.msdn.microsoft.com/windowsdesktop/DirectInput-Samples-8ac6f5e3) on MSDN Code Gallery. – Chuck Walbourn Nov 02 '14 at 18:38

2 Answers2

0

IDirectInput8A is a class, so where are you declaring it? can you copy paste the declaration? if it's a class you should add EnumDevices as a member of it.

Mast
  • 1
0

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);
101010
  • 14,866
  • 30
  • 95
  • 172