我有一个由 VS2010 生成的通用 SDI 应用程序,我想用它来测试 WinUsb API。我安装了当前版本的 WDK。根据我在其他地方阅读的帖子,我应该能够设置 VS2010 项目包含路径以指向 WDK 并添加 include WinUsb.h 来执行此操作。所以我将它添加到 stdafx.h 中,如下所示
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <Winusb.h>
但是当我编译时出现错误
1>c:\winddk\7600.16385.1\inc\api\usb200.h(93): error C2332: 'struct' : missing tag name
1>c:\winddk\7600.16385.1\inc\api\usb200.h(93): error C2011: '<unnamed-tag>' : 'enum' type redefinition
1> c:\program files (x86)\microsoft sdks\windows\v7.0a\include\htmlhelp.h(331) : see declaration of '<unnamed-tag>'
1>c:\winddk\7600.16385.1\inc\api\usb200.h(93): error C2059: syntax error : 'constant'
1>c:\winddk\7600.16385.1\inc\api\usb200.h(93): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
它提示的结构是
typedef union _USB_HIGH_SPEED_MAXPACKET {
struct _MP {
USHORT MaxPacket:11; /* 0..10 */
USHORT HSmux:2; /* 11..12 */
USHORT Reserved:3; /* 13..15 */
};
USHORT us;
} USB_HIGH_SPEED_MAXPACKET, *PUSB_HIGH_SPEED_MAXPACKET;
并且 IDE 已经在 _MP 下划了红色下划线。
最佳答案
当应用配置为使用 MBCS 时,问题的根源就出现了。
在mbctype.h
中,选择MBCS时包含的是一组#define
语句
/* bit masks for MBCS character types */
#define _MS 0x01 /* MBCS single-byte symbol */
#define _MP 0x02 /* MBCS punct */
#define _M1 0x04 /* MBCS 1st (lead) byte */
#define _M2 0x08 /* MBCS 2nd byte*/
#define _SBUP 0x10 /* SBCS upper char */
#define _SBLOW 0x20 /* SBCS lower char */
发生在包含 usb200.h
之前。
您可以不选择 MBCS(通过使用 Unicode),也可以像 Lynn 所说的那样在上面的行中选择 #undef
。但将 #include
放在列表底部附近以避免意外后果。
关于c++ - #include <WinUsb.h> 在 MFC 应用程序中产生编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30671389/