0

我正在尝试枚举 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;
}

仅供参考 - 这是使用 C 编译器的 ac 文件。

我收到了这些奇怪的错误。

error C2039: 'EnumDevices' : is not a member of 'IDirectInput8A'
error C2440: 'function' : cannot convert from 'const GUID' to 'const IID *const '

第一个是指开始的行di->EnumDevices...

第二个是指IID_IDirectInput8in DirectInput8Create

我玩过 UNICODE 设置,看看它是否重要。没有。

这感觉像是非常基本的事情。

4

2 回答 2

0

IDirectInput8A 是一个类,那么你在哪里声明它呢?你能复制粘贴声明吗?如果它是一个类,你应该添加 EnumDevices 作为它的成员。

于 2014-11-02T02:25:06.617 回答
0

我自己解决了。

由于它是 C 而不是 C++,我们需要在顶部声明所有这些:

#define CINTERFACE
#define INITGUID
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#pragma comment (lib, "dinput8.lib")

这在 DirectInput8Create 中:

 &IID_IDirectInput8,

这在枚举行中:

di->lpVtbl->EnumDevices(di, DI8DEVCLASS_GAMECTRL, deviceCountCallback, &count, DIEDFL_ATTACHEDONLY);
于 2014-11-05T13:06:24.760 回答