To communicate with USB IO Driver one must first enumerate the
Originally Posted by entsecy
device. The enumeration of the device returns a device name. This
device name is used to open the interface, using CreateFile(). Once
you have the handle from CreateFile() you can use DeviceIOControl()
to communicate to the USB IO Device and CloseHandle() to close it.
The hardest part is getting the device name the rest is simply. To send
commands to the USB IO device simply build a command packet and
submit it using the DeviceIOControl functions.
To get the device name use Windows™
device manger. To do this one calls a function in the setupapi.dll.
Simply poll the device manger with the USB I/O GUID for all the
devices that match the GUID given. The device manger will return
the device names for all the devices currently available on your
Use the DEFINE_GUID macro to build the GUID.
This GUID is passed to SetupDiGetClassDevs(), which returns a
0xb5157d69, 0x75f8, 0x11d3, 0x8c, 0xe0, 0x0, 0x20, 0x78, 0x15,
handle to the device. The enumeration functions are found in the
The first argument identifies the interface you’re looking for. The
HDEVINFO hinfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL,
NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
flag bits in the last argument indicate that you are looking for the
interfaces exported by the USB I/O device.
Once you have a handle to the device information set, you can
perform an enumeration of all the devices that export the particular
interface you’re interested in. See Microsoft function documentation
for more information on setupapi.dll library functions.
Poll the device manager till there are no matching devices left.
After this code runs you end up with a list of device names, or NULL
// an array of cstrings
for (DWORD i=0; ; ++i)
Interface_Info.cbSize = sizeof(Interface_Info);
// Enumerate device
if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
// get the required lenght
NULL, 0, &needed, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA detail =
// fill the device details
&Interface_Info,detail, needed,NULL, NULL))
strncpy(name, detail->DevicePath, sizeof(name));
Devices[i] = name;
// keep a copy of each device name
} // end of for loop
if no devices could be found (i = 0). Each device name will represent
one USB I/O device that is plugged into your computer. If you know
that you will only support one USB I/O device on your system at one
time, you can reduce the enumeration code by dropping the for loop
and only going through the code once. The device name(s) that are
returned from the above code have a port number prefixed to the
original GUID. The port number is related to order of the plug and
play devices on your machine and can not be predetermined. The
device name should look like the following.
This is the complete device name one will use in order to
communicate with the USB I/O device.