SetupDiGetClassDevsA 接口64位替代
时间: 2023-09-10 21:09:10 浏览: 35
在64位平台上,SetupDiGetClassDevsA可以被SetupDiGetClassDevs代替。它们的参数和用法是一样的,只是函数名称不同。具体如下:
```C++
HDEVINFO SetupDiGetClassDevs(
const GUID *ClassGuid,
PCTSTR Enumerator,
HWND hwndParent,
DWORD Flags
);
```
其中,ClassGuid参数指定了设备类别的GUID,Enumerator参数指定了设备的枚举器,hwndParent参数指定了窗口句柄,Flags参数指定了控制设备信息集的行为。函数返回值是一个指向设备信息集的句柄。
需要注意的是,SetupDiGetClassDevs是Unicode版本的函数,因此参数都是UNICODE字符串。如果你在使用ANSI版本的代码,需要将字符串转换为UNICODE字符串。
相关问题
用C++编写发现手机接入电脑的程序
以下是一个简单的示例程序,可以检测到手机是否连接到计算机,并在连接时打印消息。这个程序使用了Windows API。
```cpp
#include <Windows.h>
int main()
{
// 获取设备接口信息
HDEVINFO deviceInfoSet = SetupDiGetClassDevsA(NULL, "USB", NULL, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if (deviceInfoSet == INVALID_HANDLE_VALUE)
{
printf("Failed to get device info!\n");
return 1;
}
// 枚举设备接口
SP_DEVINFO_DATA deviceInfoData = { 0 };
deviceInfoData.cbSize = sizeof(deviceInfoData);
for (DWORD i = 0; SetupDiEnumDeviceInfo(deviceInfoSet, i, &deviceInfoData); i++)
{
// 获取设备描述符
char buffer[MAX_PATH] = { 0 };
if (!SetupDiGetDeviceRegistryPropertyA(deviceInfoSet, &deviceInfoData, SPDRP_DEVICEDESC, NULL, (PBYTE)buffer, sizeof(buffer), NULL))
{
continue;
}
// 检查设备描述符是否包含手机关键字
if (strstr(buffer, "Mobile") || strstr(buffer, "Android"))
{
printf("Phone connected!\n");
break;
}
}
SetupDiDestroyDeviceInfoList(deviceInfoSet);
return 0;
}
```
请注意,这只是一个简单的示例,可能无法检测所有手机连接情况。如果您需要检测更多设备,请考虑使用更专业的设备管理库。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)