本文整理匯總了Python中ctypes._CFuncPtr方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes._CFuncPtr方法的具體用法?Python ctypes._CFuncPtr怎麽用?Python ctypes._CFuncPtr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes._CFuncPtr方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WINFUNCTYPE
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _CFuncPtr [as 別名]
def WINFUNCTYPE(restype, *argtypes, **kw):
flags = _FUNCFLAG_STDCALL
if kw.pop("use_errno", False):
flags |= ctypes._FUNCFLAG_USE_ERRNO
if kw.pop("use_last_error", False):
flags |= ctypes._FUNCFLAG_USE_LASTERROR
if kw:
raise ValueError("unexpected keyword argument(s) %s" % kw.keys())
try:
return ctypes._win_functype_cache[(restype, argtypes, flags)]
except KeyError:
class WinFunctionType(ctypes._CFuncPtr):
_argtypes_ = argtypes
_restype_ = restype
_flags_ = flags
ctypes._win_functype_cache[(restype, argtypes, flags)] = WinFunctionType
return WinFunctionType
示例2: enumerate_winfuncs
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _CFuncPtr [as 別名]
def enumerate_winfuncs(self):
for obj in vars(windows.generated_def.winfuncs):
instance = eval("windows.generated_def.winfuncs." + obj)
if hasattr(instance, '__bases__') and instance.__bases__[0] is _CFuncPtr:
function_name = obj[0:-1 * len('Prototype')]
if not function_name in self.function_prototypes:
self.function_prototypes[function_name] = {}
self.function_prototypes[function_name]['restype'] = instance._restype_.__name__
argtypes = []
for argtype in instance._argtypes_:
argtypes.append(argtype.__name__)
if not argtype in self.argtypes:
self.argtypes[argtype.__name__] = 1
self.function_prototypes[function_name]['arg_types'] = argtypes
elif obj.endswith('Params'):
function_name = obj[0:-1 * len('Params')]
if not function_name in self.function_prototypes:
self.function_prototypes[function_name] = {}
self.function_prototypes[function_name]['arg_names'] = instance
示例3: test_abstract
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _CFuncPtr [as 別名]
def test_abstract(self):
from ctypes import _CFuncPtr
self.assertRaises(TypeError, _CFuncPtr, 13, "name", 42, "iid")
示例4: duplicate
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _CFuncPtr [as 別名]
def duplicate(self, other):
if callable(other):
if isinstance(other, ctypes._CFuncPtr):
other = ctypes.cast(other, ctypes.c_void_p).value
elif not isinstance(other, int):
other = ctypes.cast(other, ctypes.c_void_p).value
return self.__class__(other)
示例5: generate_callback_decorator
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import _CFuncPtr [as 別名]
def generate_callback_decorator(self, flags, restype, *argtypes, **kwargs):
_memsync_ = kwargs.pop('memsync', [])
if not(flags & _FUNCFLAG_STDCALL):
func_type_key = _FUNCFLAG_CDECL
else:
func_type_key = _FUNCFLAG_STDCALL
try:
# There already is a matching function pointer type available
return self.cache_dict['func_type'][func_type_key][(restype, argtypes, flags)]
except KeyError:
# Create new function pointer type class
class FunctionType(ctypes._CFuncPtr):
_argtypes_ = argtypes
_restype_ = restype
memsync = self.unpack_definition_memsync(_memsync_)
_flags_ = flags
# Store the new type and return
self.cache_dict['func_type'][func_type_key][(restype, argtypes, flags)] = FunctionType
return FunctionType