Python ctypes: loading DLL from from a relative path

前端 未结 4 1661
挽巷
挽巷 2020-12-15 04:40

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:



        
4条回答
  •  青春惊慌失措
    2020-12-15 05:20

    Expanding on Matthew's answer:

    import os.path
    dll_name = "MyCDLL.dll"
    dllabspath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dll_name
    myDll = ctypes.CDLL(dllabspath)
    

    This will only work from a script, not the console nor from py2exe.

提交回复
热议问题