【问题标题】:C++ XInput Compilation using g++使用 g++ 编译 C++ XInput
【发布时间】:2016-03-19 17:42:15
【问题描述】:
#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等 -LC:\Windows SDK\Lib -lXInput -o Joypad

我错过了什么吗?我用mingw x86_64

目录包括: Windows 工具包 8.1(嗯,共享,winrt) 微软 DirectX SDK

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

【问题讨论】:

标签: c++ windows compilation mingw xinput


【解决方案1】:

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

“删除”它们的一种方法是为自己创建一个头文件,例如 no_sal.h 和 每次您的 GCC 编译在 SAL 注释 __foo 上出现问题时,添加:

#define __foo

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

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

【讨论】:

  • 谢谢先生,它已成功编译.. 但似乎不像我想象的那样工作。我使用 x360ce 来支持我的通用双 USB,它不起作用,它无法识别它。顺便说一句,当我使用 Visual Studio 编译并使用 x360ce 识别我的游戏手柄时,该程序运行良好。
猜你喜欢
  • 1970-01-01
  • 2012-05-08
  • 2011-04-27
  • 1970-01-01
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 2016-02-28
相关资源
最近更新 更多