我正试图通过http://msdn.microsoft.com/en-us/library/windows/desktop/ee417001%28v=vs.85%29.aspx的XInput教程。但是,该示例中的代码甚至不会执行,因为它一直在说,除了其他错误之外,没有目标架构"。我已经浏览了整个互联网,但仍然不知道如何定义我的架构。我现在要做的就是让程序告诉我是否连接了控制器。这是我到目前为止的代码:
#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
}
}
}
我正在运行Windows 7 Professional 64位并使用Visual Studio Professional 2013.以下是我的错误(删除了空间的项目路径):
1 error C1189: #error : "No Target Architecture" c:\program files (x86)\windows kits\8.1\include\um\winnt.h 145 1
2 IntelliSense: #error directive: "No Target Architecture" c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 145 2
3 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 16918 11
4 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17529 11
5 IntelliSense: identifier "SLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17537 16
6 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17544 13
7 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17551 13
8 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17559 13
9 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17569 13
10 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\winnt.h 17576 10
11 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\minwinbase.h 358 9
12 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 51 11
13 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 59 13
14 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 67 13
15 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 81 13
16 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 94 13
17 IntelliSense: identifier "PSLIST_HEADER" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\interlockedapi.h 102 10
18 IntelliSense: identifier "CONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\processthreadsapi.h 762 16
19 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 1279 14
20 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8619 13
21 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8621 10
22 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8637 11
23 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8660 10
24 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8669 10
25 IntelliSense: identifier "PCONTEXT" is undefined c:\Program Files (x86)\Windows Kits\8.1\Include\um\WinBase.h 8685 13
此外,我已经包含了第一个错误的代码。第145行是表示&#34; No Target Architecture&#34;。下面有一条红线&#34; #error&#34;。这是:
#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
提前感谢您的帮助。我自己和其他几个人都遇到了麻烦,所以任何帮助都会受到赞赏。
答案 0 :(得分:2)
如果我理解正确,您需要定义程序将运行的平台的体系结构。例如,在你的包含之前加上#define _AMD64_
。
如果这没有帮助,也许您需要在编译器依赖项中添加一些库...这解决了我的问题。
IIRC将#include<windows.h>
放在#include<Xinput.h>
之前也可能有所帮助。