I tried to make an import for libusb-1.0.22.7z from https://libusb.info/ .
The import unit is very buggy but I could make a small program to list the usb devices.
On my machine, it gives the same results that the example program libusb-1.0.22\examples\bin64\testlibusb.exe

I've published this program and the import at https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb
You can get the corresponding binaries in this release https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb .

I used lazarus to generate and compile the console app, but I verified, you can compile it from the command line, you'll just have to change the path to you freepascal installation.

I converted the libusb.h to libusb.pas with h2pas from the lazarus plugin H2Paswizard ( https://wiki.freepascal.org/H2Paswizard ).

You'll find the project for H2Paswizard at https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb/include/libusb-1.0/project1.h2p

It's a very quick an dirty conversion. In h2paswizard I added  a rename from LIBUSB_CALL to WINAPI.

I got some problems with var parameters in functions for example I needed to change
     function libusb_open(dev: Plibusb_device; var dev_handle:Plibusb_device_handle):longint;cdecl;external name 'libusb_open';
into
    function libusb_open(dev: Plibusb_device; dev_handle:PPlibusb_device_handle):longint;cdecl;external name 'libusb_open';

I think this can be fixed by tuning some details of the import.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to