Python ctypes使用winmode加载DLL [英] Python ctypes use winmode to load DLLs

查看:547
本文介绍了Python ctypes使用winmode加载DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了一个C ++ API应用程序,该应用程序放置了两个DLL( A.DLL B.DLL )在我的程序文件夹中。 A.DLL 依赖于 B.DLL

I've installed an C++ API application which puts a couple of DLLs (A.DLL and B.DLL) in my programs folder. A.DLL has a dependency on B.DLL

我可以加载从 C:CPrograms Files\XXX-API\A.DLL ctypes.WinDLL IF成功地将它们c $ c>

I can load them successfully with ctypes.WinDLL IF from the installation folder like C:\Programs Files\XXX-API\A.DLL

而如果我将文件夹移动到另一个位置 C:\TEMP\ ,Python cytes加载将抱怨它找不到 B.DLL

while if I move the folder to another place C:\TEMP\ , the Python cytes load will complain that it can't find B.DLL.

我正在寻找 winmode ,看来它将解决该问题。 winmode 似乎从 MS参考

I'm looking into the winmode, looks like it will solve the problem. The winmode seems to take an integer from parameters in MS reference .

例如:


LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR

0x00000100

0x00000100

要使用 LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR ,将 0x00000100 作为 256 传递给 winmode ? ctype会抱怨找不到 B.DLL ,我不确定丢失了什么,感谢您的任何想法,谢谢!

To use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR ,to pass 0x00000100 as 256 to winmode ? ctype will complain can not find B.DLL,I'm not sure what's missing ,appreciate any idea from you ,thanks !

ctypes.WinDLL(path_to_A_DLL , winmode = 256 )


推荐答案

备选方案1:

import nt
_func1 = ctypes.WinDLL(lib_name, winmode = nt._LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)

替代项2:

_func1 = ctypes.WinDLL(lib_name, winmode = 0x100)

应该都可以。

但是整天都在尝试os.add_dll_directory()。最终切换到

But was trying os.add_dll_directory() all day long. Switched finally to

_func1 = ctypes.WinDLL(absolute_lib_path, winmode = 0x8)

这篇关于Python ctypes使用winmode加载DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆