当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.sizeof方法代码示例

本文整理汇总了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) 
开发者ID:mbusb,项目名称:multibootusb,代码行数:26,代码来源:gen.py

示例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) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:23,代码来源:support.py

示例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 
开发者ID:wbond,项目名称:oscrypto,代码行数:26,代码来源:_ffi.py

示例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 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:22,代码来源:pdraw.py

示例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]) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例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 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例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 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:19,代码来源:canlib.py

示例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) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:22,代码来源:canlib.py

示例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 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:20,代码来源:canlib.py

示例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 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:18,代码来源:canlib.py

示例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) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:21,代码来源:canlib.py

示例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 
开发者ID:skelsec,项目名称:minidump,代码行数:22,代码来源:createminidump.py

示例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 
开发者ID:skelsec,项目名称:minidump,代码行数:23,代码来源:privileges.py

示例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
        ]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_ctypeslib.py

示例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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_dtype.py


注:本文中的ctypes.sizeof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。