本文整理汇总了Python中ctypes.POINTER类的典型用法代码示例。如果您正苦于以下问题:Python POINTER类的具体用法?Python POINTER怎么用?Python POINTER使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了POINTER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_byref_pointer
def test_byref_pointer(self):
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
示例2: test_array_pointers
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ ia[i] for i in range(3) ], [0, 0, 0])
LPINT = POINTER(c_int)
LPINT.from_param((c_int * 3)())
self.assertRaises(TypeError, LPINT.from_param, c_short * 3)
self.assertRaises(TypeError, LPINT.from_param, c_long * 3)
self.assertRaises(TypeError, LPINT.from_param, c_uint * 3)
示例3: test_pointer_subclasses
def test_pointer_subclasses(self):
from ctypes import POINTER, c_void_p
Void_pp = POINTER(c_void_p)
class My_void_p(c_void_p):
pass
My_void_pp = POINTER(My_void_p)
o = My_void_pp()
assert Void_pp.from_param(o) is o
示例4: test_byref_pointerpointer
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
raises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
raises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
raises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
示例5: test_int_pointers
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
x = LPINT.from_param(pointer(c_int(42)))
self.assertEqual(x.contents.value, 42)
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
self.assertEqual(LPINT.from_param(None), None)
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
return
示例6: test_byref_pointer
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
示例7: test_array_pointers
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
# Pointers are only compatible with arrays containing items of
# the same type!
LPINT = POINTER(c_int)
LPINT.from_param((c_int*3)())
self.assertRaises(TypeError, LPINT.from_param, c_short*3)
self.assertRaises(TypeError, LPINT.from_param, c_long*3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
示例8: test_int_pointers
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
## p = pointer(c_int(42))
## x = LPINT.from_param(p)
x = LPINT.from_param(pointer(c_int(42)))
assert x.contents.value == 42
assert LPINT(c_int(42)).contents.value == 42
assert not LPINT.from_param(None)
if c_int != c_long:
raises(TypeError, LPINT.from_param, pointer(c_long(42)))
raises(TypeError, LPINT.from_param, pointer(c_uint(42)))
raises(TypeError, LPINT.from_param, pointer(c_short(42)))
示例9: test_int_pointers
def test_int_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER, pointer
LPINT = POINTER(c_int)
## p = pointer(c_int(42))
## x = LPINT.from_param(p)
x = LPINT.from_param(pointer(c_int(42)))
self.assertEqual(x.contents.value, 42)
self.assertEqual(LPINT(c_int(42)).contents.value, 42)
if not due_to_ironpython_bug("http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=24755"):
self.assertEqual(LPINT.from_param(None), None)
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_uint(42)))
self.assertRaises(TypeError, LPINT.from_param, pointer(c_short(42)))
示例10: __debug_create
def __debug_create(self):
"""create IDebugClient"""
self.__idebug_client = POINTER(DbgEng.IDebugClient)()
hr = DebugCreate(byref(DbgEng.IDebugClient._iid_), byref(self.__idebug_client))
if S_OK != hr:
raise Exception('DebugCreate() fail.')
else:
logger.debug('[D] DebugClient: ' + str(self.__idebug_client))
示例11: fn
def fn():
p = POINTER(c_int)()
assert not p
p.contents = c_int(12)
assert p
示例12: LibraryNotFoundError
if not security_path:
raise LibraryNotFoundError('The library Security could not be found')
Security = CDLL(security_path, use_errno=True)
Boolean = c_bool
CFIndex = c_long
CFData = c_void_p
CFString = c_void_p
CFArray = c_void_p
CFDictionary = c_void_p
CFError = c_void_p
CFType = c_void_p
CFTypeID = c_ulong
CFTypeRef = POINTER(CFType)
CFAllocatorRef = c_void_p
OSStatus = c_int32
CFDataRef = POINTER(CFData)
CFStringRef = POINTER(CFString)
CFArrayRef = POINTER(CFArray)
CFDictionaryRef = POINTER(CFDictionary)
CFErrorRef = POINTER(CFError)
SecKeyRef = POINTER(c_void_p)
SecCertificateRef = POINTER(c_void_p)
SecTransformRef = POINTER(c_void_p)
SecRandomRef = c_void_p
SecTrustSettingsDomain = c_uint32
示例13: _RAMPPTR
def _RAMPPTR(cls):
cls = POINTER(cls)
cls.from_param = classmethod(cast_from_tuple(cls.from_param))
return cls
示例14: CFUNCTYPE
FT_Int = c_int
FT_UInt = c_uint
FT_F2Dot14 = c_short
FT_Pos = FT_Fixed = FT_Long = c_long
FT_Glyph_Format = c_int
FT_String_p = c_char_p
FT_Short = c_short # A typedef for signed short.
FT_UShort = c_ushort # A typedef for unsigned short.
FT_Generic_Finalizer = CFUNCTYPE(None, c_void_p)
FT_Encoding = c_int
class FT_LibraryRec(Structure):
_fields_ = []
FT_Library = POINTER(FT_LibraryRec)
class FT_Vector(Structure):
_fields_ = [('x', FT_Pos), ('y', FT_Pos)]
class FT_UnitVector(Structure):
_fields_ = [('x', FT_F2Dot14), ('y', FT_F2Dot14)]
class FT_Matrix(Structure):
_fields_ = [('xx', FT_Fixed), ('xy', FT_Fixed),
('yx', FT_Fixed), ('yy', FT_Fixed)]
示例15: __init__
class DebugClient:
"""IDebugClient Wrapper"""
def __init__(self):
"""DebugClient initialization"""
self.__debug_create()
def __debug_create(self):
"""create IDebugClient"""
self.__idebug_client = POINTER(DbgEng.IDebugClient)()
hr = DebugCreate(byref(DbgEng.IDebugClient._iid_), byref(self.__idebug_client))
if S_OK != hr:
raise Exception('DebugCreate() fail.')
else:
logger.debug('[D] DebugClient: ' + str(self.__idebug_client))
def query_interface(self, interface):
"""IDebugClient::QueryInterface method"""
return self.__idebug_client.QueryInterface(interface)
def get_indentity(self):
"""IDebugClient::GetIdentity method"""
buffer_size = 0x100
identity_size = c_ulong(0)
hr = self.__idebug_client._IDebugClient__com_GetIdentity(None, buffer_size, byref(identity_size))
if S_OK != hr:
raise Exception('GetIdentity() fail.')
buffer_size = identity_size.value + 1
buffer = create_string_buffer(buffer_size)
hr = self.__idebug_client._IDebugClient__com_GetIdentity(buffer, buffer_size, byref(identity_size))
if S_OK != hr:
raise Exception('GetIdentity() fail.')
return buffer.value
def set_event_callbacks(self, event_callbacks):
"""IDebugClient::SetEventCallbacks method"""
hr = self.__idebug_client.SetEventCallbacks(event_callbacks)
if S_OK != hr:
raise Exception('SetEventCallbacks() fail.')
def get_event_callbacks(self):
"""IDebugClient::GetEventCallbacks method"""
return self.__idebug_client.GetEventCallbacks()
def set_output_callbacks(self, output_callbacks):
"""IDebugClient::SetOutputCallbacks method"""
hr = self.__idebug_client.SetOutputCallbacks(output_callbacks)
if S_OK != hr:
raise Exception('SetOutputCallbacks() fail.')
def get_output_callbacks(self):
"""IDebugClient::GetOutputCallbacks method"""
return self.__idebug_client.GetOutputCallbacks()
def get_running_process_ids(self):
"""IDebugClient::GetRunningProcessSystemIds method"""
server = 0
count = 256
ids = (c_ulong * count)()
actual_count = c_ulong(0)
hr = self.__idebug_client._IDebugClient__com_GetRunningProcessSystemIds(server, ids, count, byref(actual_count))
if S_OK != hr:
raise Exception('GetRunningProcessSystemIds() fail.')
return ids, actual_count.value
def get_running_process_desc(self, sysid):
"""IDebugClient::GetRunningProcessDescription method"""
try:
server = 0
flags = DbgEng.DEBUG_PROC_DESC_NO_PATHS
exename_size = 0x100
exename = create_string_buffer(exename_size)
actual_exename_size = c_ulong(0)
description_size = 0x100
description = create_string_buffer(description_size)
actual_description_size = c_ulong(0)
hr = self.__idebug_client._IDebugClient__com_GetRunningProcessDescription(
server, sysid, flags,
exename, exename_size, byref(actual_exename_size),
description, description_size, byref(actual_description_size))
if S_OK != hr:
if S_FALSE == hr:
exename_size = actual_exename_size.value + 1
#.........这里部分代码省略.........