Python ctypes: loading DLL from from a relative path
- by Frederick
I have a Python module, wrapper.py, that wraps a C DLL. The DLL lies in the same folder as the module. Therefore, I use the following code to load it:
myDll = ctypes.CDLL("MyCDLL.dll")
This works if I execute wrapper.py from its own folder. If, however, I run it from elsewhere, ctypes goes looking for DLL in the current working directory and naturally fails.
My question is, is there a way by which I can specify the DLL's path relative to the wrapper instead of the current working directory? This will enable me to ship the two together and allow the user to run/import the wrapper from anywhere.