问题描述
我正在尝试枚举 COM 端口的友好名称".端口可能会随着 USB 串行设备在运行时的连接和断开而动态变化.
I'm trying to enumerate "friendly names" for COM ports. The ports may dynamically change as USB-serial devices are connected and disconnected at runtime.
基于this question中描述的可能方法,我正在尝试使用 SetupDiGetClassDevs 方法.
Based on the possible methods described in this question, I am attempting to use the SetupDiGetClassDevs method.
我找到了 这个示例代码,但它是为旧版本的 setupapi 单元(到 homepages.borland.com 的原始链接当然不起作用).
I found this example code, but it is written for an older version of the setupapi unit (the original link to homepages.borland.com doesn't work of course).
我尝试使用当前 JVCL 中的 setupapi 单元(JVCL340CompleteJCL221-Build3845),但它似乎与 Delphi 7 不兼容.我收到编译器错误:
I tried using the setupapi unit from the current JVCL(JVCL340CompleteJCL221-Build3845), but it doesn't seem to be compatible with Delphi 7. I get compiler errors:
if SetupDiGetDeviceRegistryProperty(DevInfoHandle,DeviceInfoData,
RegProperty,
@PropertyRegDataType,
@S1[1],RequiredSize,@RequiredSize) then begin
在调用SetupDiGetDeviceRegistryProperty函数时,我在参数 @PropertyRegDataType 和 @RequiredSize 上收到错误实际参数和形式参数的类型必须相同".
In the call to function SetupDiGetDeviceRegistryProperty,I get the error "Types of actual and formal parameters must be identical" on the parameters @PropertyRegDataType, and @RequiredSize.
Delphi3000 网站说代码是在 2004 年编写的,并且是为 Delphi 7 设计的,所以我不确定为什么它现在不适用于 Delphi 7,除非 setupapi 发生了变化.是否有人熟悉可能导致这些问题的 setupapi 更改?
The Delphi3000 site says the code was written in 2004 and is intended for Delphi 7, so I'm not sure why it doesn't work with Delphi 7 now, unless setupapi has changed. Is anyone familiar with the changes to setupapi that could cause these problems?
我正在使用一个简单的控制台程序进行测试.使用语句是windows,系统工具,类,设置API,注册表;"
I'm testing with a simple console program. The uses statement is " windows, sysutils, classes, setupAPI, Registry;"
主程序是:
begin
ComPortStringList := SetupEnumAvailableComPorts;
for Index := 0 to ComPortStringList.Count - 1 do
writeln(ComPortStringList[Index]);
end;
end.
推荐答案
看起来 PDWord
类型的一些参数在 SetupApi.pas 中被替换为
var DWord
代码>.您只需要像这样从代码中的这些参数中删除@":
Looks like some arguments of type PDWord
were replaced by var DWord
in SetupApi.pas
. All you need is to remove '@' from these arguments in your code like that:
if SetupDiGetDeviceRegistryProperty(DevInfoHandle,DeviceInfoData,
RegProperty,
PropertyRegDataType,
@S1[1],RequiredSize,RequiredSize) then begin
这篇关于Delphi 中使用 SetupDiGetClassDevs 进行串口枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!