I am trying to run a simple code written with libusb-win32 on VS2010 to get information about the USB devices connected. I cannot get it run sucessfully.
#include <stdio.h>
#include <string.h>
#include "lusb0_usb.h"
int verbose = 1;
int print_device(struct usb_device *dev, int level);
int main(int argc, char *argv[])
{
struct usb_bus *bus;
if (argc > 1 && !strcmp(argv[1], "-v"))
verbose = 1;
usb_init();
usb_set_debug(255);
int nBusses = usb_find_busses();
int nDevices = usb_find_devices();
if(nDevices <=0) return 0;
for (bus = usb_get_busses(); bus; bus = bus->next)
{
if (bus->root_dev && !verbose)
print_device(bus->root_dev, 0);
else
{
struct usb_device *dev;
for (dev = bus->devices; dev; dev = dev->next)
print_device(dev, 0);
}
}
return 0;
}
The project configuration is Win32, debug and I am using the x86 dll & lib files. I am able to compile the code.
The usb_find_busses()
returns 1 & usb_find_devices()
returns 0. I do not understand why I am not getting correct numbers. Printing bus->root_dev prints the following output.
Dev #0: 0000 - 0000
bLength: 18
bDescriptorType: 01h
bcdUSB: 0200h
bDeviceClass: 09h
bDeviceSubClass: 00h
bDeviceProtocol: 00h
bMaxPacketSize0: 40h
idVendor: 0000h
idProduct: 0000h
bcdDevice: 0100h
iManufacturer: 0
iProduct: 0
iSerialNumber: 0
bNumConfigurations: 0
Couldn't retrieve descriptors
I ran the inf-wizard.exe and there I am able to see all the devices with vendor and device ids. I do not understand what I am missing.