请问能不能检测出刚插入的USB设备使用的是哪个端口号

hszj 2006-08-01 05:17:25
请问能不能检测出刚插入的USB设备使用的是哪个端口号,有没有这样的win32 API, 谢谢,因为我是开发应用软件的不懂驱动。
...全文
640 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
tanlight 2006-08-10
  • 打赏
  • 举报
回复
Edp0是默认的控制信息端口。
zhoujiamurong 2006-08-02
  • 打赏
  • 举报
回复
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
int iPosition = 0;// 串口所在的位置
CString strCom;//串口字符串

// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(NULL,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES );

if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return FALSE;
}

// Enumerate through all devices in Set.

DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
&DeviceInfoData);i++)
{
DWORD DataT;
LPTSTR buffer = NULL;
DWORD buffersize = 0;

//
// Call function with null to begin with,
// then use the returned buffer size
// to Alloc the buffer. Keep calling until
// success or an unknown failure.
//
while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_FRIENDLYNAME,//SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
if (GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
buffer = (char*)LocalAlloc(LPTR,buffersize);
}
else
{
// Insert error handling here.
break;
}
}
//串口和并口的GUID()
if(1295444344 ==DeviceInfoData.ClassGuid.Data1
&& 58149 == DeviceInfoData.ClassGuid.Data2
&& 4558 == DeviceInfoData.ClassGuid.Data3
&& 191 == DeviceInfoData.ClassGuid.Data4[0]
&& 193 == DeviceInfoData.ClassGuid.Data4[1]
&& 8 == DeviceInfoData.ClassGuid.Data4[2]
&& 0 == DeviceInfoData.ClassGuid.Data4[3]
&& 43 == DeviceInfoData.ClassGuid.Data4[4]
&& 225 == DeviceInfoData.ClassGuid.Data4[5]
&& 3 == DeviceInfoData.ClassGuid.Data4[6]
&& 24 == DeviceInfoData.ClassGuid.Data4[7])
{
//如果括号里面有COM字符串,就加进来
strCom.Format("%s",buffer);
int iLeft = strCom.Find("(");
if('C' == strCom.GetAt(iLeft + 1)
&& 'O' == strCom.GetAt(iLeft + 2)
&& 'M' == strCom.GetAt(iLeft + 3))
{
m_comboNum.AddString(buffer);
}

}

if (buffer) LocalFree(buffer);
}


if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return FALSE;
}

// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);

21,616

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧