C++ builder 使用libusb1.2.6.0 生成的exe 放在别的电脑,提示缺少libusb0.dll ,怎么做到把dll一起封装在exe中

huyue2576 2016-11-06 11:03:45
C++ builder xe2 使用 libusb1.2.6.0 生成exe,在未装libusb0.dll电脑打不开,每次都需要把dll放入新环境中,太麻烦,有什么方法可以把dll一同封装在exe中
...全文
766 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyue2576 2016-11-14
  • 打赏
  • 举报
回复
谢谢啊,但是发现这个libusb有个不好,就是每个软件的电脑都需要安装install-filter-win,感觉生无可恋啊!
ooolinux 2016-11-13
  • 打赏
  • 举报
回复
我觉得结构体定义应该放在头文件中被include,全局变量也在头文件中声明为extern。
huyue2576 2016-11-13
  • 打赏
  • 举报
回复
动态加载一些结构体定义,还有成员变量怎么处理?
huyue2576 2016-11-13
  • 打赏
  • 举报
回复
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 *)
ooolinux 2016-11-12
  • 打赏
  • 举报
回复
这样做DLL要用LoadLibrary。
huyue2576 2016-11-12
  • 打赏
  • 举报
回复
按照你给我的方式做了,没做成功,也是醉了!
ooolinux 2016-11-08
  • 打赏
  • 举报
回复
引用 6 楼 huyue2576 的回复:
干嘛好麻烦啊,具体怎么实现呢?怎么释放?
参考: http://blog.163.com/tab_98/blog/static/11924097201593161636684/
走好每一步 2016-11-07
  • 打赏
  • 举报
回复
用打包软件 Inno Setup。 再不行那你去找libusb的源码。
huyue2576 2016-11-07
  • 打赏
  • 举报
回复
干嘛好麻烦啊,具体怎么实现呢?怎么释放?
ooolinux 2016-11-06
  • 打赏
  • 举报
回复
作为资源文件,运行时释放出来再调用,不过这种做法有点不自然。
huyue2576 2016-11-06
  • 打赏
  • 举报
回复
可以让dll封装在exe中嘛?打开就可以用那种
ooolinux 2016-11-06
  • 打赏
  • 举报
回复
libusb0.dll 可以和.exe文件放在同一个目录,一起打包提供。
huyue2576 2016-11-06
  • 打赏
  • 举报
回复
直接调用libusb.lib ,然后把libusb0.dll 放进system32文件内就可以了,但后来发现这种方法不太好!放在别的电脑总需要把libusb0.dll放进去,太麻烦了
ooolinux 2016-11-06
  • 打赏
  • 举报
回复
libusb1.2.6.0 有没有提供静态lib用于静态编译?

1,316

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧