TJvHidDeviceController“DevicePath”总是显示“\”

发布于 2024-10-16 16:37:53 字数 182 浏览 10 评论 0原文

我正在使用 TJvHidDeviceController 类来检索 HID 设备信息。我已经插入了两个 HID 设备,但我试图获取 SP_DEVICE_INTERFACE_DETAIL_DATA_A 结构的“DevicePath”,但设备路径始终为“\”。所以我无法打开CreateFile函数。请帮我解决这个问题。我的操作系统win7。 谢谢大家。

I'm using TJvHidDeviceController class to retrive HID Device information. I have plugged two HID devices, but i'm trying to ge the "DevicePath" of SP_DEVICE_INTERFACE_DETAIL_DATA_A structure always getting the device path as '\'. So Ican't open CreateFile function. Please help me to solve this issue. My OS win7.
Thanks All.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2024-10-23 16:37:54

这是猜测!

我能想到的一件事是:

TJvHidDeviceController 调用 Windows API 调用而不使用 A 或 W 后缀。使用的结构是 SP_DEVICE_INTERFACE_DETAIL_DATA_A,ANSI 版本。现在,如果您使用 Delphi 2009 或更高版本,则例程将需要 SP_DEVICE_INTERFACE_DETAIL_DATA_W。尺寸相同,所以一切看起来都不错。但存储的字符串将采用 USC2 编码(WideChars)而不是 ANSI 编码 ->因此,每个 ANSI 字符后面都会有一个空字节。 TJvHidDeviceController 可能使用 StrPas 之类的函数将字符数组转换回 pascal 字符串,因此,您只能看到第一个字符。

查看:
在填充结构的函数调用之后设置一个断点,并使用 CPU 窗口以内存转储的形式查看内容。如果您每隔一个字节看到 ANSI 字符,并且在中间看到空字节,则可以确认上述情况就是这种情况。

解决方案:

  1. 检查调用是否使用宽变体并相应地更改结构。
  2. 检查调用是否使用宽变体并改用 A 变体。这可能是最简单的选择。

This is guessing!

The one thing I can think of is:

TJvHidDeviceController calls a Windows API call WITHOUT using an A or W suffix. The structure used is SP_DEVICE_INTERFACE_DETAIL_DATA_A, the ANSI version. Now, if you use Delphi 2009 or higher, the routine will expect SP_DEVICE_INTERFACE_DETAIL_DATA_W. size is the same so everything looks OK. But the strings stored will be USC2 encoded (WideChars) instead of ANSI encoded -> thus after every ANSI character there will be a null byte. TJvHidDeviceController probably converts the character array back to a pascal string using a function like StrPas and hence, you only see the first character.

Check:
Set a breakpoint just after the function call that fills the structure and use the CPU window to view the content as a memory dump. If you see ANSI characters every other byte and null bytes in between, you can confirm that the above scenario is the case.

Solution:

  1. Check if the call is using the wide variant and change the structure accordingly.
  2. Check if the call is using the wide variant and use the A variant instead. This is probably the easiest option.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文