0

我有一个由 VS2010 生成的通用 SDI 应用程序,我想用它来测试 WinUsb API。我安装了当前版本的 WDK。根据我在其他地方阅读的帖子,我应该能够将 VS2010 项目包含路径设置为指向 WDK 并添加包含 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 下划线标记为红色。

4

3 回答 3

3

当应用程序配置为使用 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放在列表底部附近以避免意外后果。

于 2016-02-10T19:21:16.523 回答
1

您将需要添加:

#undef _MP

就在Winusb.h.

我相信这是一个特定于 MFC 的问题,MFC 将其定义为预处理器符号,唯一的解决方法是专门取消定义它,以便正确写出结构。据说,这还有其他一些副作用,所以请谨慎购买。

于 2015-06-05T16:38:28.913 回答
0

实际上,我的错误不是#include 在 WinUsb.h 之前

我错误地假设 MFC 标头最终会包含 Windows.h,但由于这是一个与设备相关的应用程序,显然不是。

于 2015-06-07T18:14:24.587 回答