我正在維護使用SetupDiGetDeviceInterfaceDetail()查找有關計算機上安裝的串行端口的信息的應用程序。我在測試時注意到有一些設備,比如我的Lucent WinModem,沒有在枚舉中顯示。事實證明,我與我的公司製造的一組實現串行端口接口的設備有類似的問題。我的假設是,該設備的INF文件中缺少某些內容。有誰知道哪種情況會導致這種遺漏?爲什麼有些設備不能用SetupDiGetDeviceInterfaceDetail()枚舉?
編輯:這裏是我用來枚舉串行端口的代碼示例。我嘗試過各種標誌組合,但在行爲方面沒有發現任何顯着差異。
DEFINE_GUID(GUID_CLASS_COMPORT, 0x4d36e978, 0xe325, 0x11ce, 0xbf, 0xc1, \
0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18);
GUID *serial_port_guid = const_cast<GUID *>(&GUID_CLASS_COMPORT);
HDEVINFO device_info = INVALID_HANDLE_VALUE;
SP_DEVICE_INTERFACE_DETAIL_DATA *detail_data = 0;
device_info = SetupDiGetClassDevs(
serial_port_guid, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(device_info != INVALID_HANDLE_VALUE)
{
uint4 const detail_data_size = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) + 256;
detail_data = reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA *>(new char[detail_data_size]);
SP_DEVICE_INTERFACE_DATA ifc_data;
bool more_interfaces = true;
int rcd;
memset(&ifc_data, 0, sizeof(ifc_data));
memset(detail_data, 0, detail_data_size);
ifc_data.cbSize = sizeof(ifc_data);
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
for(uint4 index = 0; more_interfaces; ++index)
{
rcd = SetupDiEnumDeviceInterfaces(device_info, 0, serial_port_guid, index, &ifc_data);
if(rcd)
{
// we need to get the details of this device
SP_DEVINFO_DATA device_data = { sizeof(SP_DEVINFO_DATA) };
rcd = SetupDiGetDeviceInterfaceDetail(
device_info, &ifc_data, detail_data, detail_data_size, 0, &device_data);
if(rcd)
{
StrAsc device_path(detail_data->DevicePath);
byte friendly_name[256];
rcd = SetupDiGetDeviceRegistryProperty(
device_info, &device_data, SPDRP_FRIENDLYNAME, 0, friendly_name, sizeof(friendly_name), 0);
if(rcd)
{
std::for_each(
port_names.begin(),
port_names.end(),
update_friendly_name(
reinterpret_cast<char const *>(friendly_name)));
}
}
else
more_interfaces = false;
}
}
}
這是一個很好的領導,但不幸沒有描述我遇到的行爲。在我的情況下,potr可以被訪問。我在枚舉中根本看不到它。 – 2009-02-23 12:29:51
我看到了與GUID相同的參考,並將其更新爲與當前用於識別串行端口的參考相匹配。由於我自己聲明瞭GUID對象,因此我只保留相同的名稱。 – 2009-02-25 14:54:01
好的,增加了另一個有趣的網站 – lakshmanaraj 2009-02-26 04:18:51