Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Python 3.8, DLL loading changed, and the recommended way to add arbitrary directories to DLL search locations is with os.add_dll_directory(), see https://docs.python.org/3/library/os.html#os.add_dll_directory
can/interfaces/vector/xldriver.py used ctypes.util.find_library() to first get a path to the vxlapi/vxlapi64 for the DLLs; if a path was found, the DLL was loaded with ctypes.windll.LoadLibrary(), if not, a FileNotFoundError exception was manually raised.
find_library() only searches paths in os.environ['PATH'], which does not include directories added with os.add_dll_directory(), so find_library() fails if the vxlapi DLLs are located in an arbitrary (non-standard) directory, whether or not the directory was first added with add_dll_directory().
LoadLibrary() raises a FileNotFoundError if the DLL cannot be located, and it will look in the standard locations and arbitrary locations added with add_dll_directory(). So, rather than trying to find the DLL first with find_library(), simply wrap the LoadLibrary() call in a try/except block and raise any exceptions.
This has two benefits: first, it allows the vxlapi DLLs to be located in an arbitrary directory that can be added in an end-user script with os.add_dll_directory(); second, it catches other exceptions raised by LoadLibrary().
I don't know how this might affect legacy applications or if other interface drivers in the repository have the same problem with find_library(), nor am I sure how to test this beyond my local system, but I am happy to help if anyone can offer guidance.