我拿了this code 作为编写服务的示例。我以使用命令行参数的方式对主函数进行了一些更改并删除了
#define UNICODE
#define WINVER 0x502
我正在使用“MINGW”。
我收到以下错误:
usb_detect.c: In function 'ServiceMain':
usb_detect.c:123:16: error: unknown type name 'DEV_BROADCAST_DEVICEINTERFACE'
usb_detect.c:132:41: error: request for member 'dbcc_size' in something not a structure or union
usb_detect.c:132:61: error: 'DEV_BROADCAST_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:132:61: note: each undeclared identifier is reported only once for each function it appears in
usb_detect.c:133:41: error: request for member 'dbcc_devicetype' in something not a structure or union
usb_detect.c:133:60: error: 'DBT_DEVTYP_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:136:117: error: 'DEVICE_NOTIFY_SERVICE_HANDLE' undeclared (first use in this function)
usb_detect.c:136:148: error: 'DEVICE_NOTIFY_ALL_INTERFACE_CLASSES' undeclared (first use in this function)
如果我取消注释 unicode 和 winver,则不会出现错误,但命令行参数不起作用。 我也包含了 dbt.h..
最佳答案
DEV_BROADCAST_DEVICEINTERFACE
structure仅在 Windows XP 及更高版本(以及此代码依赖的其他一些 API)上受支持。除非您面向该版本的 Windows 或更高版本,否则不会在 Windows header 中定义它。
为了确保其已定义,您需要在包含 Windows.h
之前在头文件顶部显式指定 Windows 的目标版本。 p>
典型的模式看起来像这样:
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>
您尝试的代码的原始版本有这一行,您已将其删除:
#define WINVER 0x502
明确将目标 Windows 版本设置为 Windows Server 2003 (Windows NT v5.2)。删除它意味着您将恢复到最低公分母,即 XP 之前的 Windows 版本,其中未定义 DEV_BROADCAST_DEVICEINTERFACE
结构。
也不清楚为什么要删除 UNICODE
定义。现在是 2012 年,您正在构建的任何应用程序都应该以 Unicode 为目标。也保留其定义。
关于c - 未知类型名称 - MINGW 中的 'DEV_BROADCAST_DEVICEINTERFACE',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10651876/