我可以输入提示ctype类型吗?
from ctypes import *
def wrap_function(library: str, name: str, restype, argtypes) -> *What goes here*:
"""Simplify wrapping ctypes functions"""
func = library.__getattr__(name)
func.restype = restype
func.argtypes = argtypes
return func
在获得<_FuncPtr object at 0x--------->
之前创建的检查ctypes函数。如何在python中指出呢?
我尝试过
ctypes.POINTER(ctypes.CFUNCTYPE)
但失败了
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: must be a ctypes type
CFUNCTYPE
是函数原型,而不是ctypes
类型。您可以使用CFUNCTYPE
定义函数类型,然后将其包装在指针中,例如
from ctypes import *
POINTER(CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)))
您可以使用定义的类型来键入提示