Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DeviceIoControl question

DeviceIoControl question

Scheduled Pinned Locked Moved C / C++ / MFC
questionadobe
23 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Hi, Why do you need someone to show you how to do this? What have you tried so far? Did it succeed or fail? It looks like all you need to do is create a USB_DEVICE_DESCRIPTOR structure and call DeviceIoControl with the IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION control code. Best Wishes, -David Delaune

    R Offline
    R Offline
    RomTibi
    wrote on last edited by
    #7

    I've tested in VC++10: - declared locally the COMCTL for IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION - declared locally the structure USB_NODE_CONNECTION_INFORMATION and DeviceIoControl() returned NULL. GetLastError() returned ... 50 ERROR_NOT_SUPPORTED. Can you tell me why? :(( pls

    36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

    L 1 Reply Last reply
    0
    • R RomTibi

      I've tested in VC++10: - declared locally the COMCTL for IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION - declared locally the structure USB_NODE_CONNECTION_INFORMATION and DeviceIoControl() returned NULL. GetLastError() returned ... 50 ERROR_NOT_SUPPORTED. Can you tell me why? :(( pls

      36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #8

      Hi, With that error... it sounds like you are sending the control code to the wrong device. What handle are you passing to DeviceIoControl? I would suggest that you use this sample: www.intel.com/intelpress/usb/examples/DUSBVC.PDF[^] I have compiled it and confirmed that it works with the 7600.16385.1 DDK. Just paste the code from the Intel PDF file into a Multi-Byte console application created from Visual Studio. You will need to add this #include path to the project: \7600.16385.1\inc\api Copy and paste programming at its best. Best Wishes, -Copy&Paste

      R 1 Reply Last reply
      0
      • L Lost User

        Hi, With that error... it sounds like you are sending the control code to the wrong device. What handle are you passing to DeviceIoControl? I would suggest that you use this sample: www.intel.com/intelpress/usb/examples/DUSBVC.PDF[^] I have compiled it and confirmed that it works with the 7600.16385.1 DDK. Just paste the code from the Intel PDF file into a Multi-Byte console application created from Visual Studio. You will need to add this #include path to the project: \7600.16385.1\inc\api Copy and paste programming at its best. Best Wishes, -Copy&Paste

        R Offline
        R Offline
        RomTibi
        wrote on last edited by
        #9

        My project is to make an app that erases media (HDD, USB flash, USB HDD, etc.) showing some information on them. I use \\.\PhysicalDrive**X** to access the media for details on the size and type (fixed, removable, etc.). I found that the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\ keeps up-to-date the drives in order that they are attached. First it comes the first HDD - subkey "0" something like IDE\DiskWDC_WD5000BEVT-0A0RT0__________________01.01A01\5&2c0d176e&0&0.0.0, next, the next HDD ... . Then follows the USB devices, in the order that they were attached. Here comes trouble... Consider you have 1 HDD and 2 USB devices A and B. Subkey 0 holds data for the HDD. Attach A, subkey 1 holds data for A. Attach B, subkey 2 holds data for B. Detach A, subkey 1 holds data for B. Attach A, subkey 2 holds data for A. ... and all this time ... A remained \\.\PhysicalDrive**1** B remained \\.\PhysicalDrive**2** I can`t count on registry for that information, so I have to obtain them - via DeviceIoControl with a handle for \\.\PhysicalDrive**X** so I can map the devices to the description, exactly. I hope that is clear enough, now, what is my problem. :((

        36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

        L 1 Reply Last reply
        0
        • R RomTibi

          My project is to make an app that erases media (HDD, USB flash, USB HDD, etc.) showing some information on them. I use \\.\PhysicalDrive**X** to access the media for details on the size and type (fixed, removable, etc.). I found that the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\ keeps up-to-date the drives in order that they are attached. First it comes the first HDD - subkey "0" something like IDE\DiskWDC_WD5000BEVT-0A0RT0__________________01.01A01\5&2c0d176e&0&0.0.0, next, the next HDD ... . Then follows the USB devices, in the order that they were attached. Here comes trouble... Consider you have 1 HDD and 2 USB devices A and B. Subkey 0 holds data for the HDD. Attach A, subkey 1 holds data for A. Attach B, subkey 2 holds data for B. Detach A, subkey 1 holds data for B. Attach A, subkey 2 holds data for A. ... and all this time ... A remained \\.\PhysicalDrive**1** B remained \\.\PhysicalDrive**2** I can`t count on registry for that information, so I have to obtain them - via DeviceIoControl with a handle for \\.\PhysicalDrive**X** so I can map the devices to the description, exactly. I hope that is clear enough, now, what is my problem. :((

          36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #10

          Hi, Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision' Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^]. If you need to know which physical drive such as \\.\PhysicalDrive1 then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^]. If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^]. All of this info combined with the Intel sample should give you enough to uniquely identifying drives. Best Wishes, -David Delaune

          R 1 Reply Last reply
          0
          • L Lost User

            Hi, Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision' Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^]. If you need to know which physical drive such as \\.\PhysicalDrive1 then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^]. If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^]. All of this info combined with the Intel sample should give you enough to uniquely identifying drives. Best Wishes, -David Delaune

            R Offline
            R Offline
            RomTibi
            wrote on last edited by
            #11

            In this App I use DeviceIoControl to accomplish the following tasks: - enumerate the PhysicalDrive**X** devices - determine nr. of bytes to be overwritten - for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to. And all this via a HANDLE from CreateFile("\\\\.\\PhysicalDrive**X**", ...) Everything goes OK for ATA, not for USB. In my previous post I have shown an example on how you can`t rely on HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\**N** because USB devices are presented in the order they were attached. So, the question is: can I obtain with a HANDLE created by CreateFile("\\\\.\\PhysicalDrive**X**", ...) data reffering to manufacturer, type, revision for a USB attached storage device?

            36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

            L 1 Reply Last reply
            0
            • R RomTibi

              In this App I use DeviceIoControl to accomplish the following tasks: - enumerate the PhysicalDrive**X** devices - determine nr. of bytes to be overwritten - for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to. And all this via a HANDLE from CreateFile("\\\\.\\PhysicalDrive**X**", ...) Everything goes OK for ATA, not for USB. In my previous post I have shown an example on how you can`t rely on HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\**N** because USB devices are presented in the order they were attached. So, the question is: can I obtain with a HANDLE created by CreateFile("\\\\.\\PhysicalDrive**X**", ...) data reffering to manufacturer, type, revision for a USB attached storage device?

              36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #12

              RomTibi, I completely understand your problem now. You have a HANDLE to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David Delaune

              R 2 Replies Last reply
              0
              • L Lost User

                RomTibi, I completely understand your problem now. You have a HANDLE to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David Delaune

                R Offline
                R Offline
                RomTibi
                wrote on last edited by
                #13

                :rose:Thank you! I`ll do what you said. Waiting for your answer I found this: http://code.msdn.microsoft.com/CppStorageEnum-90ad5fa9[^] I`ve tested a few, it seem to work, but it is to clean up a lot, maybe to include the dll code in the main. I`ll keep you up to date with my progress. Thanks again! :)

                36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                1 Reply Last reply
                0
                • L Lost User

                  RomTibi, I completely understand your problem now. You have a HANDLE to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David Delaune

                  R Offline
                  R Offline
                  RomTibi
                  wrote on last edited by
                  #14

                  Happy 9 years and 2 days of CodeProject! :) I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull... :(

                  36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                  L 1 Reply Last reply
                  0
                  • R RomTibi

                    Happy 9 years and 2 days of CodeProject! :) I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull... :(

                    36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #15

                    RomTibi wrote:

                    Happy 9 years and 2 days of CodeProject! :)

                    Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.

                    RomTibi wrote:

                    I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...

                    Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?

                    R 2 Replies Last reply
                    0
                    • L Lost User

                      RomTibi wrote:

                      Happy 9 years and 2 days of CodeProject! :)

                      Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.

                      RomTibi wrote:

                      I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...

                      Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?

                      R Offline
                      R Offline
                      RomTibi
                      wrote on last edited by
                      #16

                      I use Windows Platform SDK Feb 2003 http://groups.google.com/group/microsoft.public.platformsdk.sdk_install/msg/087b0178f5d8159e?&hl=en&pli=1[^]

                      36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                      1 Reply Last reply
                      0
                      • L Lost User

                        RomTibi wrote:

                        Happy 9 years and 2 days of CodeProject! :)

                        Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.

                        RomTibi wrote:

                        I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...

                        Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?

                        R Offline
                        R Offline
                        RomTibi
                        wrote on last edited by
                        #17

                        My problem simplified so I posted this http://www.codeproject.com/Messages/4192965/Need-help-to-port-example-in-VS6.aspx[^] because remained still a problem to me. I hope you don`t mind. :)

                        36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                        L 1 Reply Last reply
                        0
                        • R RomTibi

                          My problem simplified so I posted this http://www.codeproject.com/Messages/4192965/Need-help-to-port-example-in-VS6.aspx[^] because remained still a problem to me. I hope you don`t mind. :)

                          36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #18

                          Hi RomTibi, No I don't mind at all. But I don't think anyone will be able to answer your question because to convert that project to VC6 takes alot of work and patience. You will just need to copy alot of Setup API structs and defines into a new header. If I have some free time this weekend I'll investigate it. Best Wishes, -David Delaune

                          R 1 Reply Last reply
                          0
                          • L Lost User

                            Hi RomTibi, No I don't mind at all. But I don't think anyone will be able to answer your question because to convert that project to VC6 takes alot of work and patience. You will just need to copy alot of Setup API structs and defines into a new header. If I have some free time this weekend I'll investigate it. Best Wishes, -David Delaune

                            R Offline
                            R Offline
                            RomTibi
                            wrote on last edited by
                            #19

                            THX!:rose::thumbsup:

                            36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                            L 1 Reply Last reply
                            0
                            • R RomTibi

                              THX!:rose::thumbsup:

                              36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #20

                              Hi, Just wanted to drop in and let you know that I have not forgotten about your issue. Unfortunately I was out of town last weekend and did not write any code. I still have it on my TODO list so let me know if you have solved your problem.

                              K 1 Reply Last reply
                              0
                              • L Lost User

                                Hi, Just wanted to drop in and let you know that I have not forgotten about your issue. Unfortunately I was out of town last weekend and did not write any code. I still have it on my TODO list so let me know if you have solved your problem.

                                K Offline
                                K Offline
                                K4HVDs
                                wrote on last edited by
                                #21

                                Thanks! Wait ...:rose:

                                L 1 Reply Last reply
                                0
                                • K K4HVDs

                                  Thanks! Wait ...:rose:

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #22

                                  Hmmmm, Who are you? Are you RomTibi?

                                  K 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Hmmmm, Who are you? Are you RomTibi?

                                    K Offline
                                    K Offline
                                    K4HVDs
                                    wrote on last edited by
                                    #23

                                    Randor wrote:

                                    Hmmmm,
                                     
                                    Who are you? Are you RomTibi?

                                    yeap ;) if u don`t mind

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups