Python-从python33.dll调用函数(访问冲突)
我有以下代码:Python-从python33.dll调用函数(访问冲突),python,dll,sublimetext3,ctypes,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) 结
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
使用升华文本运行(python3.3嵌入)使用,而不是windl。从文件中:
该类的实例的行为类似于CDLL实例,只是在函数调用期间不会释放Python GIL,并且在函数执行之后会检查Python错误标志。如果设置了错误标志,将引发Python异常
因此,这只对直接调用Python C api函数有用