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. How to use DeviceIoControl to access an external USB device from MFC

How to use DeviceIoControl to access an external USB device from MFC

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiotutorial
8 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.
  • S Offline
    S Offline
    StefanKittel
    wrote on last edited by
    #1

    Hello, from a MFC program I need to send data to an external USB Device. System: Windows XP SP3, MS Visual Studio 2008, WinDDK (most current). Because I don't have any valid documentation I used a sniffer showing me the used commands. GET_DESCRIPTOR_FROM_DEVICE and BULD_OR_INTERRUPT_TRANSFER Using CreateFile I can successfull connect to the device. But I failed to use DeviceIoControl.

    HANDLE result = CreateFile(dev_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    USBSCAN_GET_DESCRIPTOR data1;
    DWORD bytesReturned;
    BOOL b = DeviceIoControl(handle, IOCTL_GET_USB_DESCRIPTOR, NULL, 0, &data1, sizeof(USBSCAN_GET_DESCRIPTOR), &bytesReturned, NULL);

    Error C2065 "USBSCAN_GET_DESCRIPTOR" After including "usbscan.h" I get C2065 on METHOD_BUFFERED and FILE_ANY_ACCESS and C3861 on CTL_CODE. When including wdm.h I get about 107 errors in driverspecs.h and kernelspecs.h. So please, can anybody help me to get this run. Thanks Stefan

    L 1 Reply Last reply
    0
    • S StefanKittel

      Hello, from a MFC program I need to send data to an external USB Device. System: Windows XP SP3, MS Visual Studio 2008, WinDDK (most current). Because I don't have any valid documentation I used a sniffer showing me the used commands. GET_DESCRIPTOR_FROM_DEVICE and BULD_OR_INTERRUPT_TRANSFER Using CreateFile I can successfull connect to the device. But I failed to use DeviceIoControl.

      HANDLE result = CreateFile(dev_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

      USBSCAN_GET_DESCRIPTOR data1;
      DWORD bytesReturned;
      BOOL b = DeviceIoControl(handle, IOCTL_GET_USB_DESCRIPTOR, NULL, 0, &data1, sizeof(USBSCAN_GET_DESCRIPTOR), &bytesReturned, NULL);

      Error C2065 "USBSCAN_GET_DESCRIPTOR" After including "usbscan.h" I get C2065 on METHOD_BUFFERED and FILE_ANY_ACCESS and C3861 on CTL_CODE. When including wdm.h I get about 107 errors in driverspecs.h and kernelspecs.h. So please, can anybody help me to get this run. Thanks Stefan

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

      What is the USB device? It could be a USB com port, a USB network card for example. If so use the usual API to access it. COM API or sockets. Dont forget USB is just the protocol between the system and the hardware, at the app level it really is irrelevant.

      ============================== Nothing to say.

      S 1 Reply Last reply
      0
      • L Lost User

        What is the USB device? It could be a USB com port, a USB network card for example. If so use the usual API to access it. COM API or sockets. Dont forget USB is just the protocol between the system and the hardware, at the app level it really is irrelevant.

        ============================== Nothing to say.

        S Offline
        S Offline
        StefanKittel
        wrote on last edited by
        #3

        Hello, its a medical device having leds. I have the commandsets to enable or disable them. But I cannot send any commands. Stefan

        L 1 Reply Last reply
        0
        • S StefanKittel

          Hello, its a medical device having leds. I have the commandsets to enable or disable them. But I cannot send any commands. Stefan

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

          How does the system see the device? ie, in DeviceManager.

          ============================== Nothing to say.

          S 1 Reply Last reply
          0
          • L Lost User

            How does the system see the device? ie, in DeviceManager.

            ============================== Nothing to say.

            S Offline
            S Offline
            StefanKittel
            wrote on last edited by
            #5

            Hello, it shows under "custom usb devices" as "[Company Name] Familiy Device". Stefan

            L 1 Reply Last reply
            0
            • S StefanKittel

              Hello, it shows under "custom usb devices" as "[Company Name] Familiy Device". Stefan

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

              Hmm, so its not presenting itself as a well known device then. What sort of driver is sitting on the device? (ie what are the names) Is there an inf file with a custom driver for example? If so you will need documentation on the interface to that driver. The mnuf should be able to provide it.

              ============================== Nothing to say.

              S 1 Reply Last reply
              0
              • L Lost User

                Hmm, so its not presenting itself as a well known device then. What sort of driver is sitting on the device? (ie what are the names) Is there an inf file with a custom driver for example? If so you will need documentation on the interface to that driver. The mnuf should be able to provide it.

                ============================== Nothing to say.

                S Offline
                S Offline
                StefanKittel
                wrote on last edited by
                #7

                solved http://www.codeguru.com/forum/showthread.php?p=2053720

                D 1 Reply Last reply
                0
                • S StefanKittel

                  solved http://www.codeguru.com/forum/showthread.php?p=2053720

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

                  I'm thinking it would be a wee more efficient if winioctl.h and usbscan.h were added to the project's stdafx.h file.

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                  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