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.
  • 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