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;
}

im getting the __in & __out 's was not declared in this scope errors.

I used the syntax below 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

Is there something I missed? I use mingw x86_64

Directories included: Windows Kits 8.1 (um,shared,winrt) Microsoft DirectX SDK

Libraries included: XInput.lib - C:\Progra~2\Micros~4\Lib\x86

Ben Sat
  • 791
  • 1
  • 5
  • 9

1 Answers1

0

The __in and __out are Microsoft-specific SAL annotations. They are understood by the MS Visual Studio C++ compiler but not by the GCC compiler.

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:

#define __foo

to 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.

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. 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.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • Thank you sir it successfully compiled.. but doesn't seem to work like I thought it would. I used x360ce to support my generic twin usb, it didnt work, It doesnt recognize it. btw, this program works fine when I use visual studio to compile it and use x360ce to recognize my joypad. – Ben Sat Mar 20 '16 at 03:59