[英]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.