0
#include <Windows.h>
#include <XInput.h>

#include <iostream>

using namespace std;

struct Controller{
    XINPUT_STATE state;
};

class Joypad
{
public:
    int getJoystickPort()
    {
        DWORD dwResult;

        for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
        {
            XINPUT_STATE state;
            ZeroMemory(&state, sizeof(XINPUT_STATE));   

            // Simply get the state of the controller from XInput.
            dwResult = XInputGetState(i, &state);

            if (dwResult == ERROR_SUCCESS)
            {
                return((int) i);
                cout << "Joystick Port: " << i << " is connnected." << endl;
                cout << "Button " << (((int)state.Gamepad.wButtons == XINPUT_GAMEPAD_A)) << " pressed." << endl;
                cout << "LX:  " << state.Gamepad.sThumbLX << " LY: " << state.Gamepad.sThumbLY << endl;
                cout << "RX:  " << state.Gamepad.sThumbRX << " RY: " << state.Gamepad.sThumbRY << endl;
            }
            else
            {
                cout << "Joystick at Port: " << i << " is disconnected." << endl;
            }
        }
        return -1;
    }
};



void joystickStates(){
    Joypad* joypad = new Joypad;
    while (true){
        system("cls");      
        joypad->getJoystickPort();
        Sleep(1000);
    }
}

int main(){
    joystickStates();
    return 0;
}

我得到了 __in & __out 的没有在这个范围错误中声明。

我使用下面的语法 g++ Joypad.cpp -IC:\DirectSDK\Include -LC:\DirectSDK\Lib\x86 -lXinput -o Joypad

我也试过 g++ Joypad.cpp -IC:\Windows SDK~um,shared, etc -LC:\Windows SDK\Lib -lXInput -o Joypad

有什么我错过的吗?我使用 mingw x86_64

包括的目录:Windows Kits 8.1 (um,shared,winrt) Microsoft DirectX SDK

包括的库:XInput.lib - C:\Progra~2\Micros~4\Lib\x86

4

1 回答 1

0

__in__out是 Microsoft 特定的SAL注释 。MS Visual Studio C++ 编译器可以理解它们,但 GCC 编译器不能理解它们。

“删除”它们的一种方法是让自己成为一个头文件,比如说,no_sal.h每次你的 GCC 编译 barfs 上的 SAL 注释__foo时,添加:

#define __foo

no_sal.h. 然后通过传递选项确保它no_sal.h首先包含在每个编译中。g++-include /path/to/no_sal.h

但是,我不希望这会成为您尝试使用 GCC 编译 DirectX SDK 等非常“深度 Microsoft”代码时遇到的问题的终结。如果您不想使用 Visual Studio,请考虑将您的 Windows GCC 发行版从 MinGW(我猜)切换到TDM GCC 64-bit,它为 GCC 捆绑了 DirectX 头文件和库。

于 2016-03-19T19:40:36.220 回答