I have to following directory structure:
MainProject
| ...project files
| rtlsdr\\
| | rtlsdr.dll
| | ...other .dll
A DLL
may have other DLL dependencies that are not in the working directory or the system path. Therefore the system has no way of finding those dependencies if not specified explicitly. The best way I found is to add the location of the directory containing dependencies to the system path:
import os
from ctypes import *
abs_path_to_rtlsdr = 'C:\\something\\...\\rtlsdr'
os.environ['PATH'] = abs_path_to_rtlsdr + os.pathsep + os.environ['PATH']
d = CDLL('rtlsdr.dll')
Once the current session is closed, the PATH
variable will return to its original state.
Another option is to change working directory, but that might affect other module imports:
import os
os.chdir(abs_path_to_rtlsdr)
# load dll etc...