【问题标题】:Unknown type name - 'DEV_BROADCAST_DEVICEINTERFACE' in MINGW未知类型名称 - MINGW 中的“DEV_BROADCAST_DEVICEINTERFACE”
【发布时间】:2012-05-25 23:36:15
【问题描述】:

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

【问题讨论】:

    标签: c winapi service windows-services mingw


    【解决方案1】:

    DEV_BROADCAST_DEVICEINTERFACE structure 仅在 Windows XP 及更高版本(以及此代码所依赖的一些其他 API)上受支持。它不会在 Windows 标头中定义,除非您针对的是该版本的 Windows 或更高版本。

    为确保已定义,您需要在头文件的顶部明确指定您的目标 Windows 版本包含Windows.h

    典型的模式如下所示:

    #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 为目标。也保留它的定义。

    【讨论】:

    • 谢谢....对于win7我需要定义一个单独的winver吗?或者是否有任何其他通用定义可用于 xp 的所有版本。
    • 但是如果我定义 unicode 我不能在 main 中使用命令行参数...可能听起来很傻很抱歉我是新手...
    • stackoverflow.com/questions/895827/… 这个链接消除了我的疑虑...感谢堆栈溢出...真的 gr8...
    • 亲爱的 Cody,我阅读了上述链接并使用了 _tmain(int argc, TCHAR* argv[])。但仍然没有检测到我的命令行参数!!!!
    • 是的,如果您正在构建一个 Unicode 应用程序,您需要使用宽字符串。您可以显式使用wchar_t 类型,也可以使用TCHAR 宏为您处理它。对于像 main_tmain 这样的入口点也是如此。 _tmain 版本是根据UNICODE 的定义自动解析为正确符号的宏。如果您不熟悉这种行为,您将很难编写 Windows 代码。也许您应该选择一份好的 Win32 编程指南?我无法告诉您未发布的代码有什么问题。 @用户
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2018-10-27
    相关资源
    最近更新 更多