UnicodeString dllflName = ExtractFilePath(Application->ExeName) + "libusb.dll";
TResourceStream &rs=*new TResourceStream((UINT)HInstance,"libusb0",L"DLLFILE");
rs.SaveToFile(dllflName.w_str());
delete &rs;
HINSTANCE hDll = ::LoadLibraryW(dllflName.c_str());
typedef void (*USBINT)(void);
typedef struct usb_dev_handle *(*USBOPEN)(struct usb_device *dev);
typedef struct usb_bus *(*GETBUSSES)(void);
typedef int (*USBCONTROLMSG)(usb_dev_handle *dev, int requesttype, int request,
int value, int index, char *bytes, int size,
int timeout);
typedef int (*USBBULKREAD)(usb_dev_handle *dev, int ep, char *bytes, int size,
int timeout);
typedef int (*USBBULKWRITE)(usb_dev_handle *dev, int ep, char *bytes, int size,
int timeout);
if (hDll)
{
USBINT usbinit = (USBINT)::GetProcAddress(hDll, "usb_init");
USBINT usbfindbusses = (USBINT)::GetProcAddress(hDll, "usb_find_busses");
USBINT usbfinddevices = (USBINT)::GetProcAddress(hDll, "usb_find_devices");
USBOPEN usbopen=(USBOPEN)::GetProcAddress(hDll,"usb_open");
GETBUSSES usbgetbusses=(GETBUSSES)::GetProcAddress(hDll,"usb_get_busses");
USBCONTROLMSG usbcontrolmsg=(USBCONTROLMSG)::GetProcAddress(hDll,"usb_control_msg");
USBBULKREAD usbbulkread= (USBBULKREAD)::GetProcAddress(hDll,"usb_bulk_read");
USBBULKWRITE usbbulkwrite= (USBBULKWRITE)::GetProcAddress(hDll,"usb_bulk_write");
if (usbinit)
{
struct usb_bus *bus;
struct usb_device *dev;
char tmp[64];
unsigned char BUFFER_SIZE=10;
usbinit();
usbfindbusses();
usbfinddevices();
for (bus =usbgetbusses(); bus; bus = bus->next)
{
for (dev = bus->devices; dev; dev = dev->next)
{
if(dev->descriptor.idVendor ==0x0488 && dev->descriptor.idProduct==0x5850)
{
ListBox1->Items->Append("Serial : " + IntToHex(dev->descriptor.idVendor,4));
hdev = usbopen(dev);
if(hdev == NULL)
{
ListBox1->Items->Append("Open fail!");
}
if( usb_set_configuration(hdev,1)<0)
{
ListBox1->Items->Append("Serial :0 ");
}
if (usb_claim_interface(hdev, 0x00)<0) {
ListBox1->Items->Append("Serial :1 ");
}
int ret = usbcontrolmsg(hdev, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
14, /* set/get test */
2, /* test type */
0, /* interface id */
tmp, 64, 1000);
}
// ListBox1->Items->Append("Serial : " + IntToHex(dev->descriptor.idVendor,4));
}
}
但是结构体,还有dll自带的全局变量如何使用?
[BCC32 Error] dllusb.cpp(54): E2315 'next' is not a member of 'usb_bus', because the type is not yet defined
Full parser context
dllusb.cpp(18): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] dllusb.cpp(56): E2315 'devices' is not a member of 'usb_bus', because the type is not yet defined
Full parser context
dllusb.cpp(18): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] dllusb.cpp(58): E2315 'descriptor' is not a member of 'usb_device', because the type is not yet defined
Full parser context
dllusb.cpp(18): parsing: void _fastcall TForm2::Button1Click(TObject *)
[BCC32 Error] dllusb.cpp(60): E2315 'descriptor' is not a member of 'usb_device', because the type is not yet defined
Full parser context
dllusb.cpp(18): parsing: void _fastcall TForm2::Button1Click(TObject *)