c - 未知类型名称 - MINGW 中的 'DEV_BROADCAST_DEVICEINTERFACE'

标签 c winapi service windows-services mingw

我拿了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/

相关文章:

c# - 正确使用存储库/服务类

c - 带有字符串变量的 fopen 失败

c - 在 C 中将标准输入与 select() 结合使用

sql - 作为 Postgres 中另一个函数的参数的函数

android - 如果我从 Activity 中的 onCreate startService,finish() Activity 然后再次启动应用程序,会发生什么情况?

ios - 为企业自动重启 iOS 应用程序,无需越狱

c - 函数中声明的 const 变量的堆栈中是否有只读内存?

c# - 我能否始终确定通过 FindWindowEx 找到的控件的层次顺序?

c# - 获取Windows 8自动颜色主题的激活颜色

c++ - Internet Explorer 闪烁的子窗口