问题描述
我是不是畏惧我找不到这个互联网上的一个简单的答案,所以也许会有一个在未来,因为这个问题!
I'm afriad I couldn't find a simple answer for this on the internet, so maybe there will be one in the future because of this question!
我使用pywiiuse,一个python包装在Windows的C wiiuse库。我已经得到了几个简单的C例子由包括dll,头和库源的目录简单的工作。
I'm using pywiiuse, a python wrapper for the C wiiuse library on windows. I've gotten several plain C examples working simply by including the dll, header, and library in the directory of the source.
不过,我不知道放在哪里DLL,以便pywiiuse会发现它。一看源代码显示如下加载它:
However, I'm wondering where to put the dll so that pywiiuse will find it. A look at the source shows that it is loaded as follows:
dll = ctypes.cdll.wiiuse
运行实例产生一个模块未发现异常时,我有在同一目录作为我的测试示例中的DLL。
Running examples yields a module not found exception when I have the dll in the same directory as my test example.
哪里看蟒蛇为DLL?
推荐答案
借助是记录在MSDN上。这不是Python特定的,有没有办法改变从命令行选项,搜索顺序。 (不过看到其他方式来影响搜索顺序链接的文章。)
The Windows DLL search order is documented on MSDN. It's not Python-specific, and there is no way to change the search order from a command-line option. (But see the linked article for other ways to influence the search order.)
源头上做:
from _ctypes import LoadLibrary as _dlopen
我没能找到的,但presumably它是Windows LoadLibraryEx
,其行为功能类似于POSIX 功能,因为那是它是如何使用的。
I wasn't able to find the definition of LoadLibrary
in _ctypes.c
, but presumably it is a wrapper for the Windows LoadLibraryEx
function that behaves similarly to the POSIX dlopen
function, because that is how it is used.
如果您可以修改Python源使用 ctypes.CDLL
的构造函数,而不是,它应该工作:
If you can modify the Python source to use the ctypes.CDLL
constructor instead, it should work:
folder = os.path.dirname(os.path.abspath(__file__))
dll_path = os.path.join(folder, "wiiuse.dll")
dll = ctypes.CDLL(dll_path)
如果这是不可行的,你可以到猴子补丁ctypes的来处理这个具体案例,但似乎有点危险。也许只是复制DLL是在使用Python DLL的文件夹将是最简单的选择。
If that isn't viable, you may be able to monkey-patch ctypes to handle this specific case, but that seems a bit dangerous. Perhaps just copying the DLL to be in the same folder with the Python DLL would be the easiest alternative.
这篇关于哪里看蟒蛇由ctypes.cdll打开一个dll<名称>在Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!