简体   繁体   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;
}

im getting the __in & __out 's was not declared in this scope errors. 我在此范围错误中未声明获取__in和__out。

I used the syntax below g++ Joypad.cpp -IC:\\DirectSDK\\Include -LC:\\DirectSDK\\Lib\\x86 -lXinput -o Joypad 我使用了以下语法g ++ Joypad.cpp -IC:\\ DirectSDK \\ Include -LC:\\ DirectSDK \\ Lib \\ x86 -lXinput -o Joypad

and I also tried g++ Joypad.cpp -IC:\\Windows SDK~um,shared, etc -LC:\\Windows SDK\\Lib -lXInput -o Joypad 并且我还尝试了g ++ Joypad.cpp -IC:\\ Windows SDK〜um,shared等-LC:\\ Windows SDK \\ Lib -lXInput -o Joypad

Is there something I missed? 有什么我想念的吗? I use mingw x86_64 我用mingw x86_64

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

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

The __in and __out are Microsoft-specific SAL annotations. __in__out是Microsoft特定的SAL批注。 They are understood by the MS Visual Studio C++ compiler but not by the GCC compiler. MS Visual Studio C ++编译器可以理解它们,而GCC编译器则不能。

A way to "delete" them would be to make yourself a header file, say, no_sal.h and every time your GCC compilation barfs on a SAL annotation __foo , add: 一种“删除”它们的方法是使自己成为一个头文件,例如no_sal.h并且每次GCC编译在SAL批注__foo ,添加:

#define __foo

to no_sal.h . no_sal.h Then make sure that no_sal.h is included first in every compilation by passing g++ the option -include /path/to/no_sal.h . 然后,通过向g++传递-include /path/to/no_sal.h选项,确保在每个编译中首先包含no_sal.h

However, I would not expect this to be the end of your problems in attempting to compile such very "deeply Microsoft" code as the DirectX SDK with GCC. 但是,在尝试使用GCC编译DirectX SDK这样的“深层Microsoft”代码时,我不希望这会成为您问题的终结。 If you don't want to use Visual Studio then consider switching your Windows GCC distribution from MinGW (I guess) to TDM GCC 64-bit , which bundles DirectX headers and libraries for GCC. 如果您不想使用Visual Studio,则可以考虑将Windows GCC发行版从MinGW(我想)切换到TDM GCC 64位 ,它捆绑了DirectX标头和GCC库。

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

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