Python - 从 python33.dll 调用函数(访问冲突)

标签 python dll sublimetext3 ctypes

我有这个代码:

import ctypes


lib = ctypes.WinDLL('python33.dll')
print(lib['PyRun_SimpleString'])

func = lib['PyRun_SimpleString']

func.argtypes = [ctypes.c_char_p]
func.restype = ctypes.c_int

arg = "print(':P')"
arg = arg.encode('utf-8')

func(arg)

结果:

OSError: exception: access violation reading 0x00000004

使用sublime text运行(python3.3嵌入)

最佳答案

使用PyDLL ,而不是 WinDLL。来自文档:

Instances of this class behave like CDLL instances, except that the Python GIL is not released during the function call, and after the function execution the Python error flag is checked. If the error flag is set, a Python exception is raised.

Thus, this is only useful to call Python C api functions directly.

关于Python - 从 python33.dll 调用函数(访问冲突),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42217712/

相关文章:

c++ - 如何调试 Excel 对 COM 服务器的加载?

python - 第一次保存对象时,使 django 模型字段只读或在管理中禁用

python - 如何在 Python 3.5 IDLE 上导入 pandas 和 matplotlib

c# - winmd 找不到 Newtonsoft.Json.dll 文件

haml - 如何让 HAML 语法样式在 Sublime Text 中工作?

terminal - 有没有一种有效的方法可以使用 sublime Text 3 在服务器上进行远程编辑?

sublimetext - Sublime Text - 转到行和列

python - 插入空格以分隔连接的字母和数字字符串 - Python RegEx

python - "transaction interface"更新链接服务器上的表时出错

c++ - DLL如何映射到当前程序的虚拟地址空间