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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. USB Enumeration problem.

USB Enumeration problem.

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionsharepointadobewindows-admin
10 Posts 2 Posters 1 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.
  • K Offline
    K Offline
    koumodaki
    wrote on last edited by
    #1

    I am trying to enumarate an USB device. This is a regular flash drive. I am using this piece of code int main(void) { GUID USBIODS_GUID; USBIODS_GUID.Data1 = 0x4D36E967; USBIODS_GUID.Data2 = 0xE325; USBIODS_GUID.Data3 = 0x11CE; USBIODS_GUID.Data4[0] = 0xBF; USBIODS_GUID.Data4[1] = 0xC1; USBIODS_GUID.Data4[2] = 0x08; USBIODS_GUID.Data4[3] = 0x0; USBIODS_GUID.Data4[4] = 0x2B; USBIODS_GUID.Data4[5] = 0xE1; USBIODS_GUID.Data4[6] = 0x03; USBIODS_GUID.Data4[7] = 0x18; HDEVINFO hInfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); for (DWORD i=0; ; ++i) { SP_INTERFACE_DEVICE_DATA Interface_Info; Interface_Info.cbSize = sizeof(Interface_Info); Enumerate device if (!SetupDiEnumDeviceInterfaces(hInfo, NULL, (LPGUID) &USBIODS_GUID,i, &Interface_Info)) { int err = GetLastError(); SetupDiDestroyDeviceInfoList(hInfo); return(i); } } } I obtained the UID for this device from the registry. The SetupDiEnumDeviceInterfaces returns ERROR_NO_MORE_ITEMS Where have I gone wrong? Also what is the difference between functions SetupDiEnumDeviceInterfaces () and SetupDiEnumInterfaceDevice()

    D 1 Reply Last reply
    0
    • K koumodaki

      I am trying to enumarate an USB device. This is a regular flash drive. I am using this piece of code int main(void) { GUID USBIODS_GUID; USBIODS_GUID.Data1 = 0x4D36E967; USBIODS_GUID.Data2 = 0xE325; USBIODS_GUID.Data3 = 0x11CE; USBIODS_GUID.Data4[0] = 0xBF; USBIODS_GUID.Data4[1] = 0xC1; USBIODS_GUID.Data4[2] = 0x08; USBIODS_GUID.Data4[3] = 0x0; USBIODS_GUID.Data4[4] = 0x2B; USBIODS_GUID.Data4[5] = 0xE1; USBIODS_GUID.Data4[6] = 0x03; USBIODS_GUID.Data4[7] = 0x18; HDEVINFO hInfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); for (DWORD i=0; ; ++i) { SP_INTERFACE_DEVICE_DATA Interface_Info; Interface_Info.cbSize = sizeof(Interface_Info); Enumerate device if (!SetupDiEnumDeviceInterfaces(hInfo, NULL, (LPGUID) &USBIODS_GUID,i, &Interface_Info)) { int err = GetLastError(); SetupDiDestroyDeviceInfoList(hInfo); return(i); } } } I obtained the UID for this device from the registry. The SetupDiEnumDeviceInterfaces returns ERROR_NO_MORE_ITEMS Where have I gone wrong? Also what is the difference between functions SetupDiEnumDeviceInterfaces () and SetupDiEnumInterfaceDevice()

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      koumodaki wrote:

      The SetupDiEnumDeviceInterfaces returns ERROR_NO_MORE_ITEMS Where have I gone wrong?

      By possibly not reading the documentation: MemberIndex - Specifies a zero-based index into the list of interfaces in the device information set. The caller should call this function first with MemberIndex set to zero to obtain the first interface. Then, repeatedly increment MemberIndex and retrieve an interface until this function fails and GetLastError returns ERROR_NO_MORE_ITEMS.

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      K 1 Reply Last reply
      0
      • D David Crow

        koumodaki wrote:

        The SetupDiEnumDeviceInterfaces returns ERROR_NO_MORE_ITEMS Where have I gone wrong?

        By possibly not reading the documentation: MemberIndex - Specifies a zero-based index into the list of interfaces in the device information set. The caller should call this function first with MemberIndex set to zero to obtain the first interface. Then, repeatedly increment MemberIndex and retrieve an interface until this function fails and GetLastError returns ERROR_NO_MORE_ITEMS.

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        K Offline
        K Offline
        koumodaki
        wrote on last edited by
        #3

        It is set to 0. I am passing a variable i as a parameter which I have initilized to zero in the for loop

        D 1 Reply Last reply
        0
        • K koumodaki

          It is set to 0. I am passing a variable i as a parameter which I have initilized to zero in the for loop

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Did you not read that last sentence?

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          K 1 Reply Last reply
          0
          • D David Crow

            Did you not read that last sentence?

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            K Offline
            K Offline
            koumodaki
            wrote on last edited by
            #5

            I saw it and made the chages too. Still I am facting the same problem.

            D 1 Reply Last reply
            0
            • K koumodaki

              I saw it and made the chages too. Still I am facting the same problem.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              koumodaki wrote:

              I saw it and made the chages too. Still I am facting the same problem.

              So are we going to see the changed code? :confused:

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              K 1 Reply Last reply
              0
              • D David Crow

                koumodaki wrote:

                I saw it and made the chages too. Still I am facting the same problem.

                So are we going to see the changed code? :confused:

                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                K Offline
                K Offline
                koumodaki
                wrote on last edited by
                #7

                Sorry. I actually modified the code to see if I can atleast get the 1st interface. int main(void) { GUID USBIODS_GUID; USBIODS_GUID.Data1 = 0x4D36E967; USBIODS_GUID.Data2 = 0xE325; USBIODS_GUID.Data3 = 0x11CE; USBIODS_GUID.Data4[0] = 0xBF; USBIODS_GUID.Data4[1] = 0xC1; USBIODS_GUID.Data4[2] = 0x08; USBIODS_GUID.Data4[3] = 0x0; USBIODS_GUID.Data4[4] = 0x2B; USBIODS_GUID.Data4[5] = 0xE1; USBIODS_GUID.Data4[6] = 0x03; USBIODS_GUID.Data4[7] = 0x18; HDEVINFO hInfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if (hInfo == INVALID_HANDLE_VALUE) { return 1; } SP_DEVINFO_DATA DeviceInfoData; DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); SP_INTERFACE_DEVICE_DATA Interface_Info; Interface_Info.cbSize = sizeof(Interface_Info); if(!SetupDiEnumDeviceInterfaces(hInfo, &DeviceInfoData, (LPGUID) &USBIODS_GUID,0, &Interface_Info)) { int err = GetLastError(); SetupDiDestroyDeviceInfoList(hInfo); return(0); } } The function fails even now.

                D 1 Reply Last reply
                0
                • K koumodaki

                  Sorry. I actually modified the code to see if I can atleast get the 1st interface. int main(void) { GUID USBIODS_GUID; USBIODS_GUID.Data1 = 0x4D36E967; USBIODS_GUID.Data2 = 0xE325; USBIODS_GUID.Data3 = 0x11CE; USBIODS_GUID.Data4[0] = 0xBF; USBIODS_GUID.Data4[1] = 0xC1; USBIODS_GUID.Data4[2] = 0x08; USBIODS_GUID.Data4[3] = 0x0; USBIODS_GUID.Data4[4] = 0x2B; USBIODS_GUID.Data4[5] = 0xE1; USBIODS_GUID.Data4[6] = 0x03; USBIODS_GUID.Data4[7] = 0x18; HDEVINFO hInfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if (hInfo == INVALID_HANDLE_VALUE) { return 1; } SP_DEVINFO_DATA DeviceInfoData; DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); SP_INTERFACE_DEVICE_DATA Interface_Info; Interface_Info.cbSize = sizeof(Interface_Info); if(!SetupDiEnumDeviceInterfaces(hInfo, &DeviceInfoData, (LPGUID) &USBIODS_GUID,0, &Interface_Info)) { int err = GetLastError(); SetupDiDestroyDeviceInfoList(hInfo); return(0); } } The function fails even now.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Your code snippet worked fine for me. With only one item to enumerate, SetupDiEnumDeviceInterfaces() returned 0 and GetLastError() returned ERROR_NO_MORE_ITEMS as expected.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  K 1 Reply Last reply
                  0
                  • D David Crow

                    Your code snippet worked fine for me. With only one item to enumerate, SetupDiEnumDeviceInterfaces() returned 0 and GetLastError() returned ERROR_NO_MORE_ITEMS as expected.

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    K Offline
                    K Offline
                    koumodaki
                    wrote on last edited by
                    #9

                    Oh, I thought the function should return 1 because it was successful in getting the interface. Am I missing something here? Does it mean that I am able to get the interface of the device who’s GUID I have assigned to USBIODS_GUID variable passing as parameter to the function? Could you please explain to me, Mr Crow?

                    D 1 Reply Last reply
                    0
                    • K koumodaki

                      Oh, I thought the function should return 1 because it was successful in getting the interface. Am I missing something here? Does it mean that I am able to get the interface of the device who’s GUID I have assigned to USBIODS_GUID variable passing as parameter to the function? Could you please explain to me, Mr Crow?

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      koumodaki wrote:

                      Am I missing something here?

                      Yes. It will return nonzero if it completed without error, or it will return 0 if there are no more items (i.e., GetLastError() returns ERROR_NO_MORE_ITEMS).

                      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      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