Search code examples
c++windows-10c++builderwinusbc++builder-10.3-rio

WinUsb with C++ Builder 10.3 community edition


Has anyone successfully used winusb.h with Embarcadero's C++Builder 10.3 Community Edition?

I recently downloaded 10.3 this with a view to updating a PC desktop/laptop application I wrote some years ago for Windows XP (using Borland C++Builder 6), which uses WinUSB functions to drive (one at a time) three machines.

Attempting to run the executable on Windows 10 results in protection faults on USB device access - it works fine on XP, and Windows 7.

The USB device has been updated for auto recognition by Windows 10 (Thanks, P. Batard), and using Microsoft's example at How to Access a USB Device by Using WinUSB Functions, I'm confident that there's no problem with the device - it loads, and I can interrogate the descriptors, using WinUSB function calls, coded from within a Visual Studio environment on a Windows 10 computer.

Back to Embarcadero's C++Builder 10.3 Community Edition - I can write an application which will respond to button presses (compile, link and execute ok), but when I include any of the functions from winusb.h, I'm getting errors:

[ilink32 Error] Error: Unresolved external 'WinUsb_(func)' referenced from (path edited) UNITx.OBJ

Usually, I'd take this to mean I've failed to include a required header, or the path to that header (or lib) can't be resolved, but I'm pretty certain this isn't the case - the header is definitely 'included', and I've edited the IDE path to explicitly include the winusb.h and winusb.lib file directories - they are 'buried' quite deeply, but are definitely present. I've even tried copying both files to the project directory, but to no avail.

I've searched the Embarcadero community site, but can find no reference to 'winusb'.

I appreciate that this is a far more complex environment than that of C++Builder 6, and that I could very well be missing something, but I can't shake the feeling that something in the IDE isn't working as it should - other headers link ok.

Ideas, anyone please?


Solution

  • It is not enough to simply point the IDE to the folder containing Winusb.lib, you have to actually add that .lib file to your C++ project, or reference it explicitly in your C++ code using a #pragma comment(lib, "Winusb.lib") statement, otherwise the .lib file won't be passed to the linker to resolve your calls to the WinUSB functions.

    This extra step was also required of most .lib files in C++Builder 6 too, BTW.