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


Python ctypes.byref方法代码示例

本文整理汇总了Python中ctypes.byref方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.byref方法的具体用法?Python ctypes.byref怎么用?Python ctypes.byref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.byref方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: windowsRam

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [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: try_enable_ansi

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def try_enable_ansi():
            """Try enabling ANSI colors
            https://stackoverflow.com/questions/44482505/setconsolemode-returning-false-when-enabling-ansi-color-under-windows-10"""
            lpMode = wintypes.DWORD()
            handle = WINAPI._GetStdHandle(WINAPI._STDOUT)
            if WINAPI._GetConsoleMode(handle, ctypes.byref(lpMode)):
               
                if not WINAPI._SetConsoleMode(handle, lpMode.value | WINAPI._ENABLE_VIRTUAL_TERMINAL_PROCESSING):
                    return False
            else:
                return False
            
            lpMode = wintypes.DWORD()
            handle = WINAPI._GetStdHandle(WINAPI._STDERR)
            if WINAPI._GetConsoleMode(handle, ctypes.byref(lpMode)):
                if not WINAPI._SetConsoleMode(handle, lpMode.value | WINAPI._ENABLE_VIRTUAL_TERMINAL_PROCESSING):
                    return False
            else:
                return False
            
            return True 
开发者ID:mme,项目名称:vergeml,代码行数:23,代码来源:display.py

示例3: lcs

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def lcs(s, t):
    """
        Calculate the longest common subsequence between two sequences in O(min(len(x), len(y))) space and O(len(x) * len(y)) time.
        Implemented in C++.
        Since only one instance from the set of longest common subsequences is returned,
        the algorithm has the unpleasing property of not being commutative (i.e., changing
        the input vectors changes the result).
        :see: https://en.wikipedia.org/wiki/Hirschberg%27s_algorithm
        :param x: First input sequence.
        :param y: Second input sequence.
        :return: LCS(x, y)
    """
    result = create_string_buffer("\0" * min(len(s), len(t)))
    result_len = c_size_t(len(result))
    if isinstance(s, list):
        s = "".join(s)
    if isinstance(t, list):
        t = "".join(t)
    ret = _lib.hirschberg_lcs(s, len(s), t, len(t), result, byref(result_len))
    if ret == 0:
        return result[:result_len.value]
    else:
        raise RuntimeError("lcs returned error code %d" % ret) 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:25,代码来源:lcs.py

示例4: hamming_klcs

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def hamming_klcs(seqs):
    """
        Implementation of k-LCS as described in Christian Blichmann's thesis "Automatisierte Signaturgenerierung fuer Malware-Staemme" on page 52.
        This algorithm will not forcibly find THE longest common subsequence among all sequences, as the subsequence returned by the 2-LCS algorithm
        might not be the optimal one from the set of longest common subsequences.
        :see: https://static.googleusercontent.com/media/www.zynamics.com/en//downloads/blichmann-christian--diplomarbeit--final.pdf
        :param seqs: List of sequences
        :return: A shared subsequence between the input sequences. Not necessarily the longest one, and only one of several that might exist.
    """
    c_seqs_type = c_char_p * len(seqs)
    c_seqs = c_seqs_type()
    c_seqs[:] = seqs
    c_lens_type = c_size_t * len(seqs)
    c_lens = c_lens_type()
    c_lens[:] = [len(seq) for seq in seqs]
    result = create_string_buffer("\0" * min(len(seq) for seq in seqs))
    result_len = c_size_t(len(result))
    ret = _lib.hamming_klcs_c(c_seqs, c_lens, len(seqs), result, byref(result_len))
    if ret == 0:
        return result[:result_len.value]
    else:
        raise RuntimeError("lcs returned error code %d" % ret) 
开发者ID:Cisco-Talos,项目名称:BASS,代码行数:24,代码来源:lcs.py

示例5: Put

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def Put(self, name, val, flavor):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.POINTER(winapi.VARIANT),
                                       ctypes.c_long)

        paramflags = ((_In_, 'wszName'),
                      (_In_, 'pVal'),
                      (_In_, 'lFlavor'),
                      )

        _Put = prototype(IWbemQualifierSet_Put_Idx,
                         'Put',
                         paramflags)
        _Put.errcheck = winapi.RAISE_NON_ZERO_ERR
        _Put(self.this,
             name,
             ctypes.byref(val) if val else None,
             flavor
             ) 
开发者ID:fireeye,项目名称:cWMI,代码行数:22,代码来源:wmi.py

示例6: GetNames

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def GetNames(self, qualifier_name, flags, qualifier_val):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT),
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'wszQualifierName'),
                      (_In_, 'lFlags'),
                      (_In_, 'pQualifierVal'),
                      (_Out_, 'pNames'),
                      )

        _GetNames = prototype(IWbemClassObject_GetNames_Idx,
                              'GetNames',
                              paramflags)
        _GetNames.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetNames(self.this,
                               qualifier_name,
                               flags,
                               ctypes.byref(qualifier_val) if qualifier_val else None
                               )
        return_obj = ctypes.cast(wintypes.LPVOID(return_obj), ctypes.POINTER(winapi.SAFEARRAY))
        return return_obj 
开发者ID:fireeye,项目名称:cWMI,代码行数:26,代码来源:wmi.py

示例7: SetValue

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def SetValue(self, name, flags, value):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT))

        paramflags = ((_In_, 'wszName'),
                      (_In_, 'lFlags'),
                      (_In_, 'pValue'),
                      )

        _SetValue = prototype(IWbemContext_SetValue_Idx,
                              'SetValue',
                              paramflags)
        _SetValue.errcheck = winapi.RAISE_NON_ZERO_ERR
        _SetValue(self.this,
                  name,
                  flags,
                  ctypes.byref(value) if value else None
                  ) 
开发者ID:fireeye,项目名称:cWMI,代码行数:22,代码来源:wmi.py

示例8: QueryInterface

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def QueryInterface(self, riid):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.POINTER(winapi.GUID),
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'riid'),
                      (_Out_, 'ppvObject', ctypes.pointer(wintypes.LPVOID(None)))
                      )

        _QueryInterface = prototype(IUnknown_QueryInterface_Idx,
                                    'QueryInterface',
                                    paramflags)
        _QueryInterface.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_ptr = _QueryInterface(self.this,
                                     ctypes.byref(riid))
        return IUnknown(return_ptr.contents) 
开发者ID:fireeye,项目名称:cWMI,代码行数:18,代码来源:com.py

示例9: imdecode

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def imdecode(str_img, flag=1):
    """Decode image from str buffer.
    Wrapper for cv2.imdecode that uses mx.nd.NDArray

    Parameters
    ----------
    str_img : str
        str buffer read from image file
    flag : int
        same as flag for cv2.imdecode
    Returns
    -------
    img : NDArray
        decoded image in (width, height, channels)
        with BGR color channel order
    """
    hdl = NDArrayHandle()
    check_call(_LIB.MXCVImdecode(ctypes.c_char_p(str_img),
                                 mx_uint(len(str_img)),
                                 flag, ctypes.byref(hdl)))
    return mx.nd.NDArray(hdl) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:opencv.py

示例10: resize

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def resize(src, size, interpolation=cv2.INTER_LINEAR):
    """Decode image from str buffer.
    Wrapper for cv2.imresize that uses mx.nd.NDArray

    Parameters
    ----------
    src : NDArray
        image in (width, height, channels)
    size : tuple
        target size in (width, height)
    interpolation : int
        same as interpolation for cv2.imresize

    Returns
    -------
    img : NDArray
        resized image
    """
    hdl = NDArrayHandle()
    check_call(_LIB.MXCVResize(src.handle, mx_uint(size[0]), mx_uint(size[1]),
                               interpolation, ctypes.byref(hdl)))
    return mx.nd.NDArray(hdl) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:24,代码来源:opencv.py

示例11: copyMakeBorder

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def copyMakeBorder(src, top, bot, left, right, border_type=cv2.BORDER_CONSTANT, value=0):
    """Pad image border
    Wrapper for cv2.copyMakeBorder that uses mx.nd.NDArray

    Parameters
    ----------
    src : NDArray
        Image in (width, height, channels).
        Others are the same with cv2.copyMakeBorder

    Returns
    -------
    img : NDArray
        padded image
    """
    hdl = NDArrayHandle()
    check_call(_LIB.MXCVcopyMakeBorder(src.handle, ctypes.c_int(top), ctypes.c_int(bot),
                                       ctypes.c_int(left), ctypes.c_int(right),
                                       ctypes.c_int(border_type), ctypes.c_double(value),
                                       ctypes.byref(hdl)))
    return mx.nd.NDArray(hdl) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:opencv.py

示例12: set_bulk_size

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def set_bulk_size(size):
    """Set size limit on bulk execution.

    Bulk execution bundles many operators to run together.
    This can improve performance when running a lot of small
    operators sequentially.

    Parameters
    ----------
    size : int
        Maximum number of operators that can be bundled in a bulk.

    Returns
    -------
    int
        Previous bulk size.
    """
    prev = ctypes.c_int()
    check_call(_LIB.MXEngineSetBulkSize(
        ctypes.c_int(size), ctypes.byref(prev)))
    return prev.value 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:engine.py

示例13: tell

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def tell(self):
        """Returns the current position of write head.

        Example usage:
        ----------
        >>> record = mx.recordio.MXIndexedRecordIO('tmp.idx', 'tmp.rec', 'w')
        >>> print(record.tell())
        0
        >>> for i in range(5):
        ...     record.write_idx(i, 'record_%d'%i)
        ...     print(record.tell())
        16
        32
        48
        64
        80
        """
        assert self.writable
        pos = ctypes.c_size_t()
        check_call(_LIB.MXRecordIOWriterTell(self.handle, ctypes.byref(pos)))
        return pos.value 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:recordio.py

示例14: num_gpus

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def num_gpus():
    """Query CUDA for the number of GPUs present.

    Raises
    ------
    Will raise an exception on any CUDA error.

    Returns
    -------
    count : int
        The number of GPUs.

    """
    count = ctypes.c_int()
    check_call(_LIB.MXGetGPUCount(ctypes.byref(count)))
    return count.value 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:18,代码来源:context.py

示例15: _new_alloc_handle

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import byref [as 别名]
def _new_alloc_handle(shape, ctx, delay_alloc, dtype=mx_real_t):
    """Return a new handle with specified shape and context.

    Empty handle is only used to hold results.

    Returns
    -------
    handle
        A new empty `NDArray` handle.
    """
    hdl = NDArrayHandle()
    check_call(_LIB.MXNDArrayCreateEx(
        c_array_buf(mx_uint, native_array('I', shape)),
        mx_uint(len(shape)),
        ctypes.c_int(ctx.device_typeid),
        ctypes.c_int(ctx.device_id),
        ctypes.c_int(int(delay_alloc)),
        ctypes.c_int(int(_DTYPE_NP_TO_MX[np.dtype(dtype).type])),
        ctypes.byref(hdl)))
    return hdl 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:22,代码来源:ndarray.py


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