如何解码 PDEV_BROADCAST_DEVICEINTERFACE::dbcc_name?
我一直在尝试观察 USB 子系统来检测何时添加或删除设备,但在解码 PDEV_BROADCAST_DEVICEINTERFACE::dbcc_name
字段时遇到问题。我的代码基于codeproject 上的示例。
如果我在 Visual Studio 中右键单击我的 C++/CLI 应用程序并转到 Dbt.h
中的声明,我会得到:
typedef struct _DEV_BROADCAST_DEVICEINTERFACE_W {
DWORD dbcc_size;
DWORD dbcc_devicetype;
DWORD dbcc_reserved;
GUID dbcc_classguid;
wchar_t dbcc_name[1];
} DEV_BROADCAST_DEVICEINTERFACE_W, *PDEV_BROADCAST_DEVICEINTERFACE_W;
这表明该名称应该是 wchar_t
。将其输入新的 System::String 只会产生随机字符。转换 wchar_t 字符串还有更多内容吗?
[编辑]本质上我想做this 在 C++-cli 中,但我如何移植它?
I've been trying to watch a USB subsystem to detect when devices are added or removed, but I'm having trouble decoding the PDEV_BROADCAST_DEVICEINTERFACE::dbcc_name
field. My code is based on an example over on codeproject.
If I right-click in my C++/CLI application in visual studio and go to the declaration in Dbt.h
I get:
typedef struct _DEV_BROADCAST_DEVICEINTERFACE_W {
DWORD dbcc_size;
DWORD dbcc_devicetype;
DWORD dbcc_reserved;
GUID dbcc_classguid;
wchar_t dbcc_name[1];
} DEV_BROADCAST_DEVICEINTERFACE_W, *PDEV_BROADCAST_DEVICEINTERFACE_W;
Which suggests that the name should be a wchar_t
. Feeding this into a new System::String just comes up with random characters. Is there more to converting a wchar_t string?
[edit] Essentially I want to do this in C++-cli but how do I port that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道“喂养”是什么意思。使用 Marshal::PtrToStringUni() 转换字符串。如果接收此消息的窗口是使用 CreateWindowExA() 创建的,那么您需要 Marshal::PtrToStringAnsi()。
No idea what "feeding" might mean. Use Marshal::PtrToStringUni() to convert the string. If the window that receives this message was created with CreateWindowExA() then you need Marshal::PtrToStringAnsi().