Python ctypes: loading DLL from from a relative path

Posted by Frederick on Stack Overflow See other posts from Stack Overflow or by Frederick
Published on 2010-06-05T13:16:00Z Indexed on 2010/06/05 13:22 UTC
Read the original article Hit count: 207

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about ctypes