通过 Windows 的 API(用户模式)检索 PCI 坐标 [英] Retrieving PCI coordinates by Windows' API (user mode)

查看:27
本文介绍了通过 Windows 的 API(用户模式)检索 PCI 坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过使用 Windows c/c++ API(例如 PnP 配置管理器 API)来获取设备的 PCI 坐标(总线/插槽/功能编号)?我已经知道如何在内核模式下做到这一点,我需要一个用户模式解决方案.我的目标系统是 Windows XP-32 位.

Is there a way to obtain PCI coordinates (bus/slot/function numbers) of devices by using Windows c/c++ API (e.g PnP Configuration Manager API)? I already know how to do it in kernel mode, I need an user-mode solution. My target system is Windows XP-32 bit.

推荐答案

我最终找到了一个简单的解决方案(这只是深入 MSDN 的问题).

I've eventually found a simple solution (it was just a matter of digging into MSDN).

这个最少的代码根据总线/插槽/功能查找设备的 PCI 坐标:

This minimal code finds the device's PCI coordinates in terms of bus/slot/function:

DWORD bus, addr, slot, func;
HDEVINFO h; // Obtained by SetupDiGetClassDevs
SP_DEVINFO_DATA d; // Filled by SetupDiGetDeviceInterfaceDetail

SetupDiGetDeviceRegistryProperty(h,&d,SPDRP_BUSNUMBER,NULL,&bus,sizeof(bus),NULL);
SetupDiGetDeviceRegistryProperty(h,&d,SPDRP_ADDRESS,NULL,&addr,sizeof(addr),NULL);
slot = (addr >> 16) & 0xFFFF;
func = addr & 0xFFFF;

注意:对于实际生产,输出缓冲区的大小必须通过先前调用 API 函数获得才能动态分配,当然还必须添加错误检查.

Note: for real production the output buffer's size must be obtained by a previous call of the API function in order to allocate it dynamically, and error checks must be added, of course.

这篇关于通过 Windows 的 API(用户模式)检索 PCI 坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆