本文整理匯總了Python中ctypes.sizeof方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.sizeof方法的具體用法?Python ctypes.sizeof怎麽用?Python ctypes.sizeof使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes.sizeof方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: windowsRam
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def windowsRam(self):
"""
Uses Windows API to check RAM
"""
kernel32 = ctypes.windll.kernel32
c_ulong = ctypes.c_ulong
class MEMORYSTATUS(ctypes.Structure):
_fields_ = [
("dwLength", c_ulong),
("dwMemoryLoad", c_ulong),
("dwTotalPhys", c_ulong),
("dwAvailPhys", c_ulong),
("dwTotalPageFile", c_ulong),
("dwAvailPageFile", c_ulong),
("dwTotalVirtual", c_ulong),
("dwAvailVirtual", c_ulong)
]
memoryStatus = MEMORYSTATUS()
memoryStatus.dwLength = ctypes.sizeof(MEMORYSTATUS)
kernel32.GlobalMemoryStatus(ctypes.byref(memoryStatus))
return int(memoryStatus.dwTotalPhys / 1024 ** 2)
示例2: _is_gui_available
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def _is_gui_available():
UOI_FLAGS = 1
WSF_VISIBLE = 0x0001
class USEROBJECTFLAGS(ctypes.Structure):
_fields_ = [("fInherit", ctypes.wintypes.BOOL),
("fReserved", ctypes.wintypes.BOOL),
("dwFlags", ctypes.wintypes.DWORD)]
dll = ctypes.windll.user32
h = dll.GetProcessWindowStation()
if not h:
raise ctypes.WinError()
uof = USEROBJECTFLAGS()
needed = ctypes.wintypes.DWORD()
res = dll.GetUserObjectInformationW(h,
UOI_FLAGS,
ctypes.byref(uof),
ctypes.sizeof(uof),
ctypes.byref(needed))
if not res:
raise ctypes.WinError()
return bool(uof.dwFlags & WSF_VISIBLE)
示例3: array_from_pointer
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def array_from_pointer(library, name, point, size):
ffi_obj = _get_ffi(library)
array = ffi_obj.cast('%s[%s]' % (name, size), point)
total_bytes = ffi_obj.sizeof(array)
if total_bytes == 0:
return []
output = []
string_types = {
'LPSTR': True,
'LPCSTR': True,
'LPWSTR': True,
'LPCWSTR': True,
'char *': True,
'wchar_t *': True,
}
string_type = name in string_types
for i in range(0, size):
value = array[i]
if string_type:
value = ffi_obj.string(value)
output.append(value)
return output
示例4: info
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def info(self):
"""
Returns a dictionary of video frame info
"""
if self._frame_info is not None:
return self._frame_info
frame = self._get_pdraw_video_frame()
if not frame:
return self._frame_info
# convert the binary metadata into json
self._frame_info = {}
jsonbuf = ctypes.create_string_buffer(4096)
res = od.pdraw_video_frame_to_json_str(
frame, jsonbuf, ctypes.sizeof(jsonbuf))
if res < 0:
self.logger.error(
'pdraw_frame_metadata_to_json returned error {}'.format(res))
else:
self._frame_info = json.loads(str(jsonbuf.value, encoding="utf-8"))
return self._frame_info
示例5: getChannelData_Name
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_Name(self, channel):
"""Get the product name.
Retrieves the product name of the device connected to channel. The name
is returned as an ASCII string.
Args:
channel (int): The channel you are interested in
Returns:
name (string): The product name
"""
self.fn = inspect.currentframe().f_code.co_name
name = ct.create_string_buffer(80)
self.dll.canGetChannelData(channel,
canCHANNELDATA_DEVDESCR_ASCII,
ct.byref(name), ct.sizeof(name))
buf_type = ct.c_uint * 1
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(buf), ct.sizeof(buf))
return "%s (channel %d)" % (name.value, buf[0])
示例6: getChannelData_Chan_No_On_Card
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_Chan_No_On_Card(self, channel):
"""Get the channel number on the card.
Retrieves the channel number, as numbered locally on the card, device
connected to channel.
Args:
channel (int): The channel you are interested in
Returns:
number (int): The local channel number
"""
self.fn = inspect.currentframe().f_code.co_name
number = ct.c_ulong()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(number), ct.sizeof(number))
buf_type = ct.c_uint * 1
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(buf), ct.sizeof(buf))
return number.value
示例7: getChannelData_CardNumber
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_CardNumber(self, channel):
"""Get the card number
Retrieves the card's number in the computer. Each card type is numbered
separately. For example, the first PCIEcan card in a machine will have
number 0, the second PCIEcan number 1, etc.
Args:
channel (int): The channel you are interested in
Returns:
card_number (int): The device's card number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_NUMBER,
ct.byref(buf), ct.sizeof(buf))
return buf.value
示例8: getChannelData_EAN
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_EAN(self, channel):
"""Get EAN code
Retrieves the EAN number for the device connected to channel. If there
is no EAN number, "00-00000-00000-0" will be returned.
Args:
channel (int): The channel you are interested in
Returns:
ean (str): The device's EAN number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong * 2
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_UPC_NO,
ct.byref(buf), ct.sizeof(buf))
(ean_lo, ean_hi) = struct.unpack('LL', buf)
return "%02x-%05x-%05x-%x" % (ean_hi >> 12,
((ean_hi & 0xfff) << 8) | (ean_lo >> 24),
(ean_lo >> 4) & 0xfffff, ean_lo & 0xf)
示例9: getChannelData_Serial
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_Serial(self, channel):
"""Get device serial number
Retrieves the serial number for the device connected to channel. If the
device does not have a serial number, 0 is returned.
Args:
channel (int): The channel you are interested in
Returns:
serial (int): The device serial number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong * 2
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_SERIAL_NO,
ct.byref(buf), ct.sizeof(buf))
(serial_lo, serial_hi) = struct.unpack('LL', buf)
# serial_hi is always 0
return serial_lo
示例10: getChannelData_DriverName
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_DriverName(self, channel):
"""Get device driver name
Retrieves the name of the device driver (e.g. "kcany") for the device
connected to channel. The device driver names have no special meanings
and may change from a release to another.
Args:
channel (int): The channel you are interested in
Returns:
name (str): The device driver name
"""
self.fn = inspect.currentframe().f_code.co_name
name = ct.create_string_buffer(80)
self.dll.canGetChannelData(channel,
canCHANNELDATA_DRIVER_NAME,
ct.byref(name), ct.sizeof(name))
return name.value
示例11: getChannelData_Firmware
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def getChannelData_Firmware(self, channel):
"""Get device firmware version
Retrieves the firmvare version numbers for the device connected to
channel.
Args:
channel (int): The channel you are interested in
Returns:
major (int): The major version number
minor (int): The minor version number
build (int): The build number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ushort * 4
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_FIRMWARE_REV,
ct.byref(buf), ct.sizeof(buf))
(build, release, minor, major) = struct.unpack('HHHH', buf)
return (major, minor, build)
示例12: enum_pids
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def enum_pids():
max_array = c_ulong * 4096 # define long array to capture all the processes
pProcessIds = max_array() # array to store the list of processes
pBytesReturned = c_ulong() # the number of bytes returned in the array
#EnumProcess
res = EnumProcesses(
ctypes.byref(pProcessIds),
ctypes.sizeof(pProcessIds),
ctypes.byref(pBytesReturned)
)
if res == 0:
logging.error(WinError(get_last_error()))
return []
# get the number of returned processes
nReturned = int(pBytesReturned.value/ctypes.sizeof(c_ulong()))
return [i for i in pProcessIds[:nReturned]]
#https://msdn.microsoft.com/en-us/library/windows/desktop/ms683217(v=vs.85).aspx
示例13: enable_debug_privilege
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def enable_debug_privilege():
"""
Try to assign the symlink privilege to the current process token.
Return True if the assignment is successful.
"""
# create a space in memory for a TOKEN_PRIVILEGES structure
# with one element
size = ctypes.sizeof(TOKEN_PRIVILEGES)
size += ctypes.sizeof(LUID_AND_ATTRIBUTES)
buffer = ctypes.create_string_buffer(size)
tp = ctypes.cast(buffer, ctypes.POINTER(TOKEN_PRIVILEGES)).contents
tp.count = 1
tp.get_array()[0].enable()
tp.get_array()[0].LUID = get_debug_luid()
token = get_process_token()
res = AdjustTokenPrivileges(token, False, tp, 0, None, None)
if res == 0:
raise RuntimeError("Error in AdjustTokenPrivileges")
ERROR_NOT_ALL_ASSIGNED = 1300
return ctypes.windll.kernel32.GetLastError() != ERROR_NOT_ALL_ASSIGNED
示例14: test_padded_union
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def test_padded_union(self):
dt = np.dtype(dict(
names=['a', 'b'],
offsets=[0, 0],
formats=[np.uint16, np.uint32],
itemsize=5,
))
ct = np.ctypeslib.as_ctypes_type(dt)
assert_(issubclass(ct, ctypes.Union))
assert_equal(ctypes.sizeof(ct), dt.itemsize)
assert_equal(ct._fields_, [
('a', ctypes.c_uint16),
('b', ctypes.c_uint32),
('', ctypes.c_char * 5), # padding
])
示例15: test_union_with_struct_packed
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import sizeof [as 別名]
def test_union_with_struct_packed(self):
class Struct(ctypes.Structure):
_pack_ = 1
_fields_ = [
('one', ctypes.c_uint8),
('two', ctypes.c_uint32)
]
class Union(ctypes.Union):
_fields_ = [
('a', ctypes.c_uint8),
('b', ctypes.c_uint16),
('c', ctypes.c_uint32),
('d', Struct),
]
expected = np.dtype(dict(
names=['a', 'b', 'c', 'd'],
formats=['u1', np.uint16, np.uint32, [('one', 'u1'), ('two', np.uint32)]],
offsets=[0, 0, 0, 0],
itemsize=ctypes.sizeof(Union)
))
self.check(Union, expected)