C++ Xbox 360控制器API不合作
我正在努力完成XInput教程。然而,示例中的代码甚至不会执行,因为它一直在说,除其他错误外,“没有目标体系结构”。我浏览了整个互联网,仍然不知道如何定义我的架构。我现在要做的就是让程序告诉我控制器是否连接。以下是我目前掌握的代码:C++ Xbox 360控制器API不合作,c++,architecture,visual-studio-2013,xbox360,xinput,C++,Architecture,Visual Studio 2013,Xbox360,Xinput,我正在努力完成XInput教程。然而,示例中的代码甚至不会执行,因为它一直在说,除其他错误外,“没有目标体系结构”。我浏览了整个互联网,仍然不知道如何定义我的架构。我现在要做的就是让程序告诉我控制器是否连接。以下是我目前掌握的代码: #include <Xinput.h> #include <Windows.h> void main(){ DWORD dwResult; // Retrieve the state of the controller
#include <Xinput.h>
#include <Windows.h>
void main(){
DWORD dwResult;
// Retrieve the state of the controller
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){
// Controller is connected
}
else
{
// Controller is not connected
}
}
}
此外,我还包含了第一个错误的代码。第145行表示“无目标架构”。“错误”下面有一条红线。这是:
#if defined(_AMD64_) || defined(_X86_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif defined(_IA64_) || defined(_ARM_)
#define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
#elif !defined(RC_INVOKED)
#error "No Target Architecture"
#endif
提前谢谢你的帮助。我和其他几个人在这方面遇到了麻烦,因此,如果能提供任何帮助,我们将不胜感激。如果我理解正确,您需要定义您的程序将在其上运行的平台的体系结构。因此,例如,将
#define _AMD64
放在include之前
如果这没有帮助,也许您需要向编译器依赖项添加一些库……这就解决了我的问题
IIRC将#include
放在#include
前面也会有所帮助
#if defined(_AMD64_) || defined(_X86_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif defined(_IA64_) || defined(_ARM_)
#define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
#elif !defined(RC_INVOKED)
#error "No Target Architecture"
#endif