繁体   English   中英

使用g ++的C ++ XInput编译

[英]C++ XInput Compilation using g++

#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 Kits 8.1(um,shared,winrt)Microsoft DirectX SDK

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

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

一种“删除”它们的方法是使自己成为一个头文件,例如no_sal.h并且每次GCC编译在SAL批注__foo ,添加:

#define __foo

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

但是,在尝试使用GCC编译DirectX SDK这样的“深层Microsoft”代码时,我不希望这会成为您问题的终结。 如果您不想使用Visual Studio,则可以考虑将Windows GCC发行版从MinGW(我想)切换到TDM GCC 64位 ,它捆绑了DirectX标头和GCC库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM