2

I am trying to communicate with a USB printer using c-function CreateFile and therefore i need the device path. I know that i can get the device path by SetupDiEnumDeviceInterfaces and SetupDiGetDeviceInterfaceDetail, but for SetupDiEnumDeviceInterfaces i need to give an InterfaceClassGuid as third parameter which I don't know.

My current approach is:

  1. OpenPrinter with the "user friendly" name of the Printer
  2. GetPrinterDataEx with "PnpData" and "DeviceInstanceId" as parameters 2 and 3 which gives me the DeviceInstanceId
  3. ClosePrinter
  4. SetupDiCreateDeviceInfoList (with NULL-parameters)
  5. SetupDiOpenDeviceInfo with the DeviceInstanceId obtained in step 2. Now I have the DeviceInfo of the printer
  6. CM_Get_Parent with the DevInst of the printer (obtained in step 5).
  7. CM_Get_Device_ID of the parent (obtained in step 6)
  8. SetupDiOpenDeviceInfo with the device id obtained in step 7. Now I have the DeviceInfo of the USB-Interface (but not the interface itself) and am almost at the end.

The only missing thing is to get the device interface (SP_DEVICE_INTERFACE_DATA) when I have the SP_DEVINFO_DATA. The other way would be easy: Having the SP_DEVICE_INTERFACE_DATA, I could call SetupDiGetDeviceInterfaceDetail, so basically I am looking for the opposite function of SetupDiGetDeviceInterfaceDetail.

If it would be possible to enumerate ALL interfaces without having to know the InterfaceClassGuid, I could iterate through the list of interfaces and look for the one that is pointing to my device, but unfortunately, this is not possible.

The following articles were very helpful on my way: Figuring which printer name corresponds to which device ID AND http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/51449be7-a4fa-476b-8cd2-b8933bfa3294/enumerate-multifunction-printer-in-vc?forum=wdk

Am I missing something?

Community
  • 1
  • 1

1 Answers1

0

It's been awhile, so I imagine you already found the answer. I'll answer it anyway for someone who may find this question later. I believe the answer is to call SetupDiEnumDeviceInterfaces passing in your SP_DEVINFO_DATA as the second parameter. From the documentation:

A pointer to an SP_DEVINFO_DATA structure that specifies a device information element in DeviceInfoSet. This parameter is optional and can be NULL. If this parameter is specified, SetupDiEnumDeviceInterfaces constrains the enumeration to the interfaces that are supported by the specified device. If this parameter is NULL, repeated calls to SetupDiEnumDeviceInterfaces return information about the interfaces that are associated with all the device information elements in DeviceInfoSet. This pointer is typically returned by SetupDiEnumDeviceInfo.

Malaise
  • 705
  • 3
  • 8
  • 20
  • But in `SetupDiEnumDeviceInterfaces` function you have a required `InterfaceClassGuid` parameter, but the main problem is that you don't know any device interface class GUIDs before you enumerate them. A vicious circle. – Yarik Sep 25 '15 at 17:04
  • I think you can pass in the generic interface class here for just USB devices though. https://msdn.microsoft.com/en-us/library/windows/hardware/ff545972(v=vs.85).aspx but it's been awhile since I worked on this, so I may be wrong about that. – Malaise Sep 25 '15 at 23:03