如何列出系统中的所有设备啊? 比如usb设备,pci设备....
解决方案 »
- 千千静听的选择框 是网页 还是普通控件 怎么做容易实现 内存站的少
- 得到IE地址栏内容的代码,为什么不好使?
- 让工具栏显示文字的问题!
- 如何使日历控件中的某个日期黑体显示啊?
- BHO下invoke函数参数中*pDispParams->rgvarg[0]究竟是什么用处啊?
- 看看这个问题!
- SetProperty为什么不好用?
- 大家帮帮忙。。谁那有DOS的引导区,源程序。。。
- 为什么我的classview突然看不到各个类了阿?!急救!!!
- 在对话框中,如何实现打开某文件文件?
- winsock1.1服务器接收到客户端的数据后,是不是一次接收的数据,可能是客户发送了几次的数据包的和,如何拆?
- 如何屏蔽CRichEditCtrl的拷贝,粘贴,剪切事件?
【枚举系统中已经安装的所有硬件设备】 taianmonkey [原作]
关键字 枚举,硬件设备
出处
实现的主要部分代码: #include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#pragma comment(lib,"Setupapi.lib")CListBox m_strList;
........
枚举所有硬件设备的主要实现代码:m_strList.ResetContent();
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
// Create a HDEVINFO with all present devices.
hDevInfo = SetupDiGetClassDevs(NULL,0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// Insert error handling here.
return ;
}// 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_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;
}
}
m_strList.AddString(buffer);
if (buffer)
LocalFree(buffer);
}
if ( GetLastError()!=NO_ERROR &&GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return ;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
}测试环境:WINXP,WIN2000以上操作系统!