【发布时间】: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