Python ctypes.POINTER Examples

The following are 30 code examples of ctypes.POINTER(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ctypes , or try the search function .
Example #1
Source File: com.py    From cWMI with Apache License 2.0 9 votes vote down vote up
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) 
Example #2
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Clone(self):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_Out_, 'ppNewCopy'),
                      )

        _Clone = prototype(IWbemContext_Clone_Idx,
                           'Clone',
                           paramflags)
        _Clone.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _Clone(self.this
                            )
        try:
            return_obj = IWbemContext(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #3
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
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
             ) 
Example #4
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Next(self, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(BSTR),
                                       ctypes.POINTER(winapi.VARIANT),
                                       ctypes.POINTER(CIMTYPE),
                                       ctypes.POINTER(ctypes.c_long))

        paramflags = ((_In_, 'lFlags'),
                      (_Out_, 'strName'),
                      (_Out_, 'pVal'),
                      (_Out_, 'pType'),
                      (_Out_, 'plFlavor'),
                      )

        _Next = prototype(IWbemClassObject_Next_Idx,
                          'Next',
                          paramflags)
        _Next.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj, return_obj2, return_obj3, return_obj4 = _Next(self.this,
                                                                  flags
                                                                  )
        return_obj = winapi.convert_bstr_to_str(return_obj)
        return return_obj, return_obj2, return_obj3, return_obj4 
Example #5
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetNames(self, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

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

        _GetNames = prototype(IWbemQualifierSet_GetNames_Idx,
                              'GetNames',
                              paramflags)
        _GetNames.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetNames(self.this,
                               flags
                               )
        return_obj = ctypes.cast(wintypes.LPVOID(return_obj), ctypes.POINTER(winapi.SAFEARRAY))
        return return_obj 
Example #6
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetQualifierSet(self):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_Out_, 'ppQualSet'),
                      )

        _GetQualifierSet = prototype(IWbemClassObject_GetQualifierSet_Idx,
                                     'GetQualifierSet',
                                     paramflags)
        _GetQualifierSet.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetQualifierSet(self.this
                                      )
        try:
            return_obj = IWbemQualifierSet(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #7
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Get(self, name, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT),
                                       ctypes.POINTER(ctypes.c_long))

        paramflags = ((_In_, 'wszName'),
                      (_In_, 'lFlags'),
                      (_Out_, 'pVal'),
                      (_Out_, 'plFlavor'),
                      )

        _Get = prototype(IWbemQualifierSet_Get_Idx,
                         'Get',
                         paramflags)
        _Get.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj, return_obj2 = _Get(self.this,
                                       name,
                                       flags
                                       )
        return return_obj, return_obj2 
Example #8
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Put(self, name, flags, val, type_param):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT),
                                       CIMTYPE)

        paramflags = ((_In_, 'wszName'),
                      (_In_, 'lFlags'),
                      (_In_, 'pVal'),
                      (_In_, 'Type'),
                      )

        _Put = prototype(IWbemClassObject_Put_Idx,
                         'Put',
                         paramflags)
        _Put.errcheck = winapi.RAISE_NON_ZERO_ERR
        _Put(self.this,
             name,
             flags,
             ctypes.byref(val) if val else None,
             type_param
             ) 
Example #9
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
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 
Example #10
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Clone(self):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_Out_, 'ppCopy'),
                      )

        _Clone = prototype(IWbemClassObject_Clone_Idx,
                           'Clone',
                           paramflags)
        _Clone.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _Clone(self.this
                            )
        try:
            return_obj = IWbemClassObject(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #11
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Get(self, name, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT),
                                       ctypes.POINTER(CIMTYPE),
                                       ctypes.POINTER(ctypes.c_long))

        paramflags = ((_In_, 'wszName'),
                      (_In_, 'lFlags'),
                      (_Out_, 'pVal'),
                      (_Out_, 'pType'),
                      (_Out_, 'plFlavor'),
                      )

        _Get = prototype(IWbemClassObject_Get_Idx,
                         'Get',
                         paramflags)
        _Get.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj, return_obj2, return_obj3 = _Get(self.this,
                                                    name,
                                                    flags
                                                    )
        return return_obj, return_obj2, return_obj3 
Example #12
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def NextAsync(self, count, sink):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.ULONG,
                                       ctypes.POINTER(IWbemObjectSink))

        paramflags = ((_In_, 'uCount'),
                      (_In_, 'pSink'),
                      )

        _NextAsync = prototype(IEnumWbemClassObject_NextAsync_Idx,
                               'NextAsync',
                               paramflags)
        _NextAsync.errcheck = winapi.RAISE_NON_ZERO_ERR
        _NextAsync(self.this,
                   count,
                   sink.this if sink else None
                   ) 
Example #13
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Clone(self):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_Out_, 'ppEnum'),
                      )

        _Clone = prototype(IEnumWbemClassObject_Clone_Idx,
                           'Clone',
                           paramflags)
        _Clone.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _Clone(self.this
                            )
        try:
            return_obj = IEnumWbemClassObject(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #14
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetResultObject(self, timeout):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'lTimeout'),
                      (_Out_, 'ppResultObject'),
                      )

        _GetResultObject = prototype(IWbemCallResult_GetResultObject_Idx,
                                     'GetResultObject',
                                     paramflags)
        _GetResultObject.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetResultObject(self.this,
                                      timeout
                                      )
        try:
            return_obj = IWbemClassObject(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #15
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetResultString(self, timeout):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(BSTR))

        paramflags = ((_In_, 'lTimeout'),
                      (_Out_, 'pstrResultString'),
                      )

        _GetResultString = prototype(IWbemCallResult_GetResultString_Idx,
                                     'GetResultString',
                                     paramflags)
        _GetResultString.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetResultString(self.this,
                                      timeout
                                      )
        return_obj = winapi.convert_bstr_to_str(return_obj)
        return return_obj 
Example #16
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetResultServices(self, timeout):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'lTimeout'),
                      (_Out_, 'ppServices'),
                      )

        _GetResultServices = prototype(IWbemCallResult_GetResultServices_Idx,
                                       'GetResultServices',
                                       paramflags)
        _GetResultServices.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetResultServices(self.this,
                                        timeout
                                        )
        try:
            return_obj = IWbemServices(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #17
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Indicate(self, object_count, obj_array):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'lObjectCount'),
                      (_In_, 'apObjArray'),
                      )

        _Indicate = prototype(IWbemObjectSink_Indicate_Idx,
                              'Indicate',
                              paramflags)
        _Indicate.errcheck = winapi.RAISE_NON_ZERO_ERR
        _Indicate(self.this,
                  object_count,
                  obj_array.this if obj_array else None
                  ) 
Example #18
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetNames(self, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

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

        _GetNames = prototype(IWbemContext_GetNames_Idx,
                              'GetNames',
                              paramflags)
        _GetNames.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetNames(self.this,
                               flags
                               )
        return_obj = ctypes.cast(wintypes.LPVOID(return_obj), ctypes.POINTER(winapi.SAFEARRAY))
        return return_obj 
Example #19
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def Next(self, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(BSTR),
                                       ctypes.POINTER(winapi.VARIANT))

        paramflags = ((_In_, 'lFlags'),
                      (_Out_, 'pstrName'),
                      (_Out_, 'pValue'),
                      )

        _Next = prototype(IWbemContext_Next_Idx,
                          'Next',
                          paramflags)
        _Next.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj, return_obj2 = _Next(self.this,
                                        flags
                                        )
        return_obj = winapi.convert_bstr_to_str(return_obj)
        return return_obj, return_obj2 
Example #20
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
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
                  ) 
Example #21
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def GetValue(self, name, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       wintypes.LPCWSTR,
                                       ctypes.c_long,
                                       ctypes.POINTER(winapi.VARIANT))

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

        _GetValue = prototype(IWbemContext_GetValue_Idx,
                              'GetValue',
                              paramflags)
        _GetValue.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _GetValue(self.this,
                               name,
                               flags
                               )
        return return_obj 
Example #22
Source File: wmi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def QueryObjectSink(self, flags):
        prototype = ctypes.WINFUNCTYPE(HRESULT,
                                       ctypes.c_long,
                                       ctypes.POINTER(wintypes.LPVOID))

        paramflags = ((_In_, 'lFlags'),
                      (_Out_, 'ppResponseHandler'),
                      )

        _QueryObjectSink = prototype(IWbemServices_QueryObjectSink_Idx,
                                     'QueryObjectSink',
                                     paramflags)
        _QueryObjectSink.errcheck = winapi.RAISE_NON_ZERO_ERR
        return_obj = _QueryObjectSink(self.this,
                                      flags
                                      )
        try:
            return_obj = IWbemObjectSink(return_obj)
        except WindowsError:
            return_obj = None
        return return_obj 
Example #23
Source File: torch.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def _init_torch_module():
    """List and add all the torch backed ndarray functions to current module."""
    plist = ctypes.POINTER(FunctionHandle)()
    size = ctypes.c_uint()
    check_call(_LIB.MXListFunctions(ctypes.byref(size),
                                    ctypes.byref(plist)))

    module_obj = sys.modules[__name__]
    for i in range(size.value):
        hdl = FunctionHandle(plist[i])
        function = _make_torch_function(hdl)
        # if function name starts with underscore, register as static method of NDArray
        if function is not None:
            setattr(module_obj, function.__name__, function)

# Initialize the NDArray module 
Example #24
Source File: symbol.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def list_inputs(self):
        """Lists all arguments and auxiliary states of this Symbol.

        Returns
        -------
        inputs : list of str
            List of all inputs.

        Examples
        --------
        >>> bn = mx.sym.BatchNorm(name='bn')
        >>> bn.list_arguments()
        ['bn_data', 'bn_gamma', 'bn_beta']
        >>> bn.list_auxiliary_states()
        ['bn_moving_mean', 'bn_moving_var']
        >>> bn.list_inputs()
        ['bn_data', 'bn_gamma', 'bn_beta', 'bn_moving_mean', 'bn_moving_var']
        """
        size = ctypes.c_uint()
        sarr = ctypes.POINTER(ctypes.c_char_p)()
        check_call(_LIB.NNSymbolListInputNames(
            self.handle, 0, ctypes.byref(size), ctypes.byref(sarr)))
        return [py_str(sarr[i]) for i in range(size.value)] 
Example #25
Source File: symbol.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def list_attr(self, recursive=False):
        """Gets all attributes from the symbol.

        Example
        -------
        >>> data = mx.sym.Variable('data', attr={'mood': 'angry'})
        >>> data.list_attr()
        {'mood': 'angry'}

        Returns
        -------
        ret : Dict of str to str
            A dictionary mapping attribute keys to values.
        """
        if recursive:
            raise DeprecationWarning("Symbol.list_attr with recursive=True has been deprecated. "
                                     "Please use attr_dict instead.")
        size = mx_uint()
        pairs = ctypes.POINTER(ctypes.c_char_p)()
        f_handle = _LIB.MXSymbolListAttrShallow
        check_call(f_handle(self.handle, ctypes.byref(size), ctypes.byref(pairs)))
        return {py_str(pairs[i * 2]): py_str(pairs[i * 2 + 1]) for i in range(size.value)} 
Example #26
Source File: ndarray.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def shape(self):
        """Tuple of array dimensions.

        Examples
        --------
        >>> x = mx.nd.array([1, 2, 3, 4])
        >>> x.shape
        (4L,)
        >>> y = mx.nd.zeros((2, 3, 4))
        >>> y.shape
        (2L, 3L, 4L)
        """
        ndim = mx_uint()
        pdata = ctypes.POINTER(mx_uint)()
        check_call(_LIB.MXNDArrayGetShape(
            self.handle, ctypes.byref(ndim), ctypes.byref(pdata)))
        return tuple(pdata[:ndim.value]) # pylint: disable=invalid-slice-index 
Example #27
Source File: base.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def ctypes2numpy_shared(cptr, shape):
    """Convert a ctypes pointer to a numpy array.

    The resulting NumPy array shares the memory with the pointer.

    Parameters
    ----------
    cptr : ctypes.POINTER(mx_float)
        pointer to the memory region

    shape : tuple
        Shape of target `NDArray`.

    Returns
    -------
    out : numpy_array
        A numpy array : numpy array.
    """
    if not isinstance(cptr, ctypes.POINTER(mx_float)):
        raise RuntimeError('expected float pointer')
    size = 1
    for s in shape:
        size *= s
    dbuffer = (mx_float * size).from_address(ctypes.addressof(cptr.contents))
    return np.frombuffer(dbuffer, dtype=np.float32).reshape(shape) 
Example #28
Source File: base.py    From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 6 votes vote down vote up
def ctypes2buffer(cptr, length):
    """Convert ctypes pointer to buffer type.

    Parameters
    ----------
    cptr : ctypes.POINTER(ctypes.c_char)
        Pointer to the raw memory region.
    length : int
        The length of the buffer.

    Returns
    -------
    buffer : bytearray
        The raw byte memory buffer.
    """
    if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)):
        raise TypeError('expected char pointer')
    res = bytearray(length)
    rptr = (ctypes.c_char * length).from_buffer(res)
    if not ctypes.memmove(rptr, cptr, length):
        raise RuntimeError('memmove failed')
    return res 
Example #29
Source File: winapi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def SafeArrayAccessData(sa):
    prototype = ctypes.WINFUNCTYPE(
        HRESULT,
        ctypes.POINTER(SAFEARRAY),
        ctypes.POINTER(wintypes.LPVOID)
    )

    paramflags = (
        (_In_, 'psa'),
        (_Out_, 'ppvData', ctypes.pointer(wintypes.LPVOID(None))),
    )

    _SafeArrayAccessData = prototype(('SafeArrayAccessData', oleaut32), paramflags)
    _SafeArrayAccessData.errcheck = RAISE_NON_ZERO_ERR
    return_obj = _SafeArrayAccessData(sa)
    return return_obj.contents 
Example #30
Source File: winapi.py    From cWMI with Apache License 2.0 6 votes vote down vote up
def CoCreateInstance(clsid, unk, ctx, iid):
    prototype = ctypes.WINFUNCTYPE(
        HRESULT,
        ctypes.POINTER(GUID),
        wintypes.LPVOID,
        wintypes.DWORD,
        ctypes.POINTER(GUID),
        ctypes.POINTER(wintypes.LPVOID)
    )

    paramflags = (
        (_In_, 'rclsid'),
        (_In_, 'pUnkOuter'),
        (_In_, 'dwClsContext'),
        (_In_, 'riid'),
        (_Out_, 'ppv')
    )

    _CoCreateInstance = prototype(('CoCreateInstance', ole32), paramflags)
    _CoCreateInstance.errcheck = RAISE_NON_ZERO_ERR
    return _CoCreateInstance(clsid, unk, ctx, iid)