Windows will enumerate video devices, so application can see list of devices.
I wonder how windows do that in details, so I can handle order of devices.
I expect that order of devices in the list never change unless hardware changes, but actual depends on windows implementation( no document found).
For example, in ffmpeg dshow they use this to enumerate devices:
hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
enum_moniker, 0);
No official document from windows will tell us how it works when scanning device list.
I tried to search all document but not found good one.
You’ve got this huge “Device Manager” abstraction layer sitting in between the device drivers and the application (furthermore not all devices are hardware — a video source can be a software decompressor just as easily as a camera). And your case has another abstraction layer (DirectShow) sitting between Device Manager and your application.
Although Windows does indeed enumerate PCIe hardware (to load drivers and add device nodes to Device Manager), you shouldn’t much care how that happens. You’re interested in how that list is presented to you.
If the list the application sees is related at all to the order of hardware enumeration, that’s luck, and you should not depend on it, because it can’t be guaranteed. For example, if a driver gets updated, all the device nodes associated with the old driver are going away and new ones for the new driver are being created some time later, and nothing changed in the hardware at all. If a particular driver creates its device nodes in a particular order, that will be stable, but still not a good idea to rely on, because it will be vendor-specific.
These APIs provide you with identifiers that are consistent across executions. Instead of storing indexes into the device list and then having problems when the list order changes, store the values that’s intended for persistent identification.
1