Home > Software engineering >  USB with CreateFile () to open the USB device, how to fill out the devicepath this value?
USB with CreateFile () to open the USB device, how to fill out the devicepath this value?

Time:09-17

Question origin:
https://bbs.csdn.net/topics/390907217? Page=1 # post - 403471959
The brothers there is a problem in many years ago using USB: use CreateFile () open the USB device, how to fill out the devicepath this value?
He is described as:
Want to pass the ReadFile () and WriteFile () the two interfaces to access the usb device, said the document before you call the two interfaces need to calling CreateFile () to obtain the handle, and calling CreateFile () you need to specify the portname + endpoint index number, the problem is, the portname is how to get? Find MSDN that need to use IStiDeviceControl: : GetMyDevicePortName () to obtain, the header file for: Stiusd. J h, the interface is in the application layer of the call?
I don't see a lot of reply, to the point, especially those irresponsible people just post some code simply won't run, rubbish!

After I am not involved in the USB programming under the WINDOW, the USB is old stuff! Mature but why no reply? In order to solve this problem, I did some research, finally solved the problem, because in that post reply reply only five times, so I concentrate here write the experience to solve the problem here:

Positive answer this question first: the CreateFile function used devicepath GUID for the devicepath is through the equipment, this equipment GUID is specific to son if the son equipment is equipment of GUID, when access to the child with equipment GUID devicepath can be used directly, no need to seek what portname + endpoint index number, may according to the specific equipment devicepath GUID for equipment would include the so-called "portname + endpoint index number" (this I don't know), the following is my journey, carefully watching the should be able to solve the problem,

In order to facilitate problem solving and is highly recommended to download tool software UsbTreeView and BusHound

Four years on, the original poster and others have a solution?
My computer has a usb flash drive, drive is H, using UsbTreeView know the U disk VID=0 x090c, pid=0 x1000,

To use the GUID GUID_DEVINTERFACE_USB_DEVICE VID=0 x090c, pid=0 x1000
And several main function SetupDiGetClassDevs, SetupDiEnumDeviceInterfaces, SetupDiGetDeviceInterfaceDetail access device path DevicePath as "\ \ \ \? \ \ usb# vid_090c & amp; Pid_1000 # 5 & amp; 8 b518d6 & amp; 0& 3 # {a5dcbf10-6530-11-901 - f - 00 c04fb951ed d2} "; (note that some Numbers will change, in this string may be related to different USB plug),
Use the DevicePath executive CreateFile function and configure corresponding parameters can obtain handle, but access to handle and use strDeviceName="\ \ \ \. \ \ H:"; The string (drive) to obtain the handle value is different, as different results of the subsequent use DeviceIoControl to read/write device, with the former method for handle failure in reading and writing, after a direct drive is used to collect the handle to the execution DeviceIoControl can successfully read data, don't know what reason!!!!!!!!!!!!!!!

In addition, when using the GUID GUID_DEVINTERFACE_USB_DEVICE HidD_GetAttributes function cannot be used, I am here to test this function can only be used for HID device,

My question is a common not how to obtain similar usb device "\ \ \ \. \ \ H:" such a "file name to" provide CreateFile??????

Respect of the building and all the friends care about this post, although the post for the past 4 years, but some of us are focus and concern on this post, can't let people don't move!

Get into the business, a reply on the Device mentioned in the Path I use tools UsbTreeView, see two discovered a place with a function to obtain the same with me, another is:
\ \? \ usbstor# disk& Ven_usb & amp; Prod_flash_disk & amp; Rev_1100 # 6 & amp; Ef43437 & amp; 0 # {f56307-53 f2 d0 b6bf - 11-94-00 a0c91efb8b},
This time I use this generation into the CreateFile function for handle, although with "\ \ \ \. \ \ H:" get handle value is different, but can also be successfully read follow-up,
I'm surprised found the DevicePath Child Device 1 DevicePath!!!!!!!!!!

So now I am a preliminary answer your question (use CreateFile () to open the usb device, how to fill out the devicepath this value? ), usually used in my last reply method can obtain devicepath, if there is no equipment, then directly use the devicepath cooperate CreateFile access to handle, if there is a child devices, temporarily I also have no way to get his son devicepath devices, but you can use tools UsbTreeView, (UsbTreeView this tool can be downloaded on the Internet to), the hope can help you,

Problem: how to programmatically access devicepath child devices?

The following is UsbTreeView for usb drive part of the information is used to describe


+ + + + + + + + + + + + + + + + + Device Information + + + + + + + + + + + + + + + + + +
Device Description: USB mass storage Device
The Device Path: \ \? \ usb# vid_090c & amp; Pid_1000 # 5 & amp; 8 b518d6 & amp; 0& 3 # {a5dcbf10-6530-11-901 - f - 00 c04fb951ed d2}
The Device ID: USB \ VID_090C & amp; PID_1000\5 & amp; 8 b518d6 & amp; 0& 3
The Hardware IDs: USB \ VID_090C & amp; PID_1000 & amp; REV_1100 USB \ VID_090C & amp; PID_1000
Driver KeyName: {36 fc9e60 - c465-11 cf - 0000 8056-44455354} \ 0070 (GUID_DEVCLASS_USB)
Driver: system32 \ DRIVERS \ USBSTOR. SYS (Version: 6.1.7600.16385 Date: 2009-07-14)
The Driver Inf: C: \ Windows \ Inf \ usbstor Inf
Legacy BusType: PNPBus
Class: USB
Class GUID: {36 fc9e60 c465-11 cf - 0000} 8056-44455354 (GUID_DEVCLASS_USB)
Interface GUID: {a5dcbf10-6530-11-901 - f - 00 c04fb951ed d2} (GUID_DEVINTERFACE_USB_DEVICE)
Service: USBSTOR
Enumerator: USB
The Location Info: Port_ # 0003. Hub_ # 0001
The Location of IDs: PCIROOT (0) # PCI (1400) # USBROOT (0) # USB (3)
The Container ID: {b577a458 b617-11 e8 - a8c8-28 e3472d3289}
Manufacturer Info: compatible with USB storage devices
"Capabilities: 0 xc4 (Removable, RawDeviceOK SurpriseRemovalOK)
Status: 0 x0180600a (DN_DRIVER_LOADED DN_STARTED, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
The Problem Code: 0
Address: 3
Power State: D0 (supported: D0, D3, wake the from D0)
Child Device 1: USB Flash Disk, USB Device (Disk drives) (Disk1)
DevicePath: \ \? \ usbstor# disk& Ven_usb & amp; Prod_flash_disk & amp; Rev_1100 # 6 & amp; Ef43437 & amp; 0 # {f56307-53 f2 d0 b6bf - 11-94-00 a0c91efb8b}
The Device ID: USBSTOR \ DISK& VEN_USB & amp; PROD_FLASH_DISK & amp; REV_1100\6 & amp; EF43437 & amp; 0
Class: DiskDrive
Volume: \ \? \ Volume {b577a45b b617-11 e8 - a8c8-28 e3472d3289} \
The Kernel Name: \ Device \ HarddiskVolume7
The Mountpoint: H: \

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Question, when we get the Child Device of the DevicePath insert U disk into another USB port after found the DevicePath are become such as I here two different USB port for the value is:
StrDeviceName="\ \ \ \? \ \ usbstor# disk& Ven_usb & amp; Prod_flash_disk & amp; Rev_1100 # 6 & amp; Ef43437 & amp; 0 # {f56307-53 f2 d0 b6bf - 11-94-00 a0c91efb8b} ";
StrDeviceName="\ \ \ \? \ \ usbstor# disk& Ven_usb & amp; Prod_flash_disk & amp; Rev_1100 # 6 & amp; B867c1f & amp; 0 # {f56307-53 f2 d0 b6bf - 11-94-00 a0c91efb8b} ";

So we urgently need to programming to obtain the value automatically,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related