Python导入dll
如何将 winDLL 导入到 python 中并能够使用它的所有功能?它只需要双打和字符串。
How would I import a winDLL into python and be able to use all of its functions? It only needs doubles and strings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您已标记问题 ctypes ,所以听起来您已经知道答案。
ctypes 教程< /a> 非常好。一旦您阅读并理解了,您将能够轻松地做到这一点。
例如:
我自己的代码中的一个示例:
You've tagged the question ctypes and so it sounds like you already know the answer.
The ctypes tutorial is excellent. Once you've read and understood that you'll be able to do it easily.
For example:
And an example from my own code:
我发布我的经历。首先,尽管我付出了很多艰苦的工作才能将所有部分组合在一起,但导入 C# dll 很容易。我这样做的方法是:
1)安装这个nuget包(我不是所有者,只是非常有用)以构建非托管dll:https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagementexports
2) 您的 C# dll 代码如下:
3)你的Python代码是这样的:
I'm posting my experience. First of all despite all the hard work that take me to put all pieces together, importing a C# dll is easy. The way I did it is:
1) Install this nuget package (i'm not owner, is just very useful) in order to build a unmanaged dll: https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
2) Your C# dll code is like this:
3) Your python code is like this:
c 型 注意!
使用
WinDLL
(以及wintypes
、msvcrt
)是 Windows 特定的导入,并不总是有效,即使在 Windows 上也是如此!原因是它取决于你的Python安装。是本机 Windows(或使用 Cygwin 或 WSL)吗?对于ctypes,更可移植和正确的方法是使用
cdll
,如下所示:c-types NOTE!
Using
WinDLL
(andwintypes
,msvcrt
) is windows specific imports and does not always work, even on windows! The reason is that it depends on your python installation. Is it native Windows (or using Cygwin or WSL)?For ctypes, the more portable and correct way is to use
cdll
like this:使用 Cython 来访问 DLL 并为其生成 Python 绑定。
Use Cython, both to access the DLLs, and to generate Python bindings for them.
将 dll 文件保存在“C:\Windows”位置的 System32 或 SysWOW64 文件夹中。使用 python
ctypes
或cffi
库。如果您使用 cffi 库:或者
它对我有用。
Keep dlls file in System32 or SysWOW64 folder in your 'C:\Windows' location. Use python
ctypes
orcffi
library. If you use cffi library:Or
It's working for me.