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


Python ctypes.c_wchar_p方法代码示例

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


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

示例1: _create_windows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def _create_windows(source, destination, link_type):
    """Creates hardlink at destination from source in Windows."""

    if link_type == HARDLINK:
        import ctypes
        from ctypes.wintypes import BOOL
        CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW
        CreateHardLink.argtypes = [
            ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p
        ]
        CreateHardLink.restype = BOOL

        res = CreateHardLink(destination, source, None)
        if res == 0:
            raise ctypes.WinError()
    else:
        raise NotImplementedError("Link type unrecognized.") 
开发者ID:getavalon,项目名称:core,代码行数:19,代码来源:link.py

示例2: _get_long_path_name

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def _get_long_path_name(path):
        """Get a long path name (expand ~) on Windows using ctypes.

        Examples
        --------

        >>> get_long_path_name('c:\\docume~1')
        u'c:\\\\Documents and Settings'

        """
        try:
            import ctypes
        except ImportError:
            raise ImportError('you need to have ctypes installed for this to work')
        _GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
        _GetLongPathName.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p,
            ctypes.c_uint ]

        buf = ctypes.create_unicode_buffer(260)
        rv = _GetLongPathName(path, buf, 260)
        if rv == 0 or rv > 260:
            return path
        else:
            return buf.value 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:path.py

示例3: open

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def open(self):
        access = self.GENERIC_READ
        share_mode = self.FILE_SHARE_READ
        if self._allow_write:
            access |= self.GENERIC_WRITE
            share_mode |= self.FILE_SHARE_WRITE
            attributes = 0
        else:
            attributes = self.FILE_ATTRIBUTE_READONLY

        handle = kernel32.CreateFileW(
            ctypes.c_wchar_p(self._path),
            access,
            share_mode,
            0,
            self.OPEN_EXISTING,
            attributes,
            0)
        if handle == self.INVALID_HANDLE_VALUE:
            raise exception.WindowsCloudbaseInitException(
                'Cannot open file: %r')
        self._handle = handle
        self._sector_size, self._disk_size, self.fixed =\
            self._get_geometry() 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:disk.py

示例4: rmtree

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def rmtree(self, path) :
    if node_variables.NODE_JS_OS == "win" :
      import string
      from ctypes import windll, c_int, c_wchar_p
      UNUSUED_DRIVE_LETTER = ""
      for letter in string.ascii_uppercase:
        if not os.path.exists(letter+":") :
          UNUSUED_DRIVE_LETTER = letter+":"
          break
      if not UNUSUED_DRIVE_LETTER :
        sublime.message_dialog("Can't remove node.js! UNUSUED_DRIVE_LETTER not found.")
        return
      DefineDosDevice = windll.kernel32.DefineDosDeviceW
      DefineDosDevice.argtypes = [ c_int, c_wchar_p, c_wchar_p ]
      DefineDosDevice(0, UNUSUED_DRIVE_LETTER, path)
      try:
        shutil.rmtree(UNUSUED_DRIVE_LETTER)
      except Exception as e:
        print("Error: "+traceback.format_exc())
      finally:
        DefineDosDevice(2, UNUSUED_DRIVE_LETTER, path)  
    else :
      shutil.rmtree(path) 
开发者ID:pichillilorenzo,项目名称:JavaScript-Completions,代码行数:25,代码来源:installer.py

示例5: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def __init__(self, *args):
        assert self.__class__ != VectorBase, 'Instantiation of abstract class.'

        self._data = None
        if args:
            if isinstance(args[0], (long, ctypes.c_voidp, ctypes.c_void_p, ctypes.c_char_p, ctypes.c_wchar_p, ctypes.c_long)):
                self._ptr = args[0]
            elif isinstance(args[0], self.__class__):
                self._ptr = _dllHandle.Vector_Copy(args[0]._ptr)
            else:
                assert len(
                    args) == self.__class__._size and self.__class__._size <= 4, 'Attempting to constructor vector of size {} with either wrong number of arguments {} or beyond maximum size 4.'.format(
                    self.__class__._size, args)
                data = (ctypes.c_float * 4)(*(list(args) + [0] * (4 - self.__class__._size)))
                self._ptr = _dllHandle.Vector_FromFloat4(data)
        else:
            self._ptr = _dllHandle.Vector_Vector() 
开发者ID:trevorvanhoof,项目名称:sqrmelon,代码行数:19,代码来源:wrapper.py

示例6: checkFirmwareType

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def checkFirmwareType(self):
        # Load in kernel32.dll
        kernel32_dll = ctypes.WinDLL("C:\\Windows\\System32\\kernel32.dll")

        # Because we're using bogus parameters in the function call, it
        # should always fail (return 0).
        if kernel32_dll.GetFirmwareEnvironmentVariableW(ctypes.c_wchar_p(""),
            ctypes.c_wchar_p("{00000000-0000-0000-0000-000000000000}"), None,
            ctypes.c_int(0)) == 0:
            # Check the last error returned to determine firmware type.
            # If the error is anything other than ERROR_INVALID_FUNCTION
            # or ERROR_NOACCESS, raise an exception.
            last_error = ctypes.GetLastError()
            if last_error == self._ERROR_INVALID_FUNCTION:
                return "Legacy"
            elif last_error == self._ERROR_NOACCESS:
                return "UEFI"
            else:
                raise ctypes.WinError()
        else:
            return "Unknown"

    # Check for PAE, SMEP, SMAP, and NX hardware support using CPUID. 
开发者ID:nsacyber,项目名称:Splunk-Assessment-of-Mitigation-Implementations,代码行数:25,代码来源:ae.py

示例7: _copyWindows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def _copyWindows(text):
    GMEM_DDESHARE = 0x2000
    CF_UNICODETEXT = 13
    d = ctypes.windll # cdll expects 4 more bytes in user32.OpenClipboard(None)
    try:  # Python 2
        if not isinstance(text, unicode):
            text = text.decode('mbcs')
    except NameError:
        if not isinstance(text, str):
            text = text.decode('mbcs')
    d.user32.OpenClipboard(None)
    d.user32.EmptyClipboard()
    hCd = d.kernel32.GlobalAlloc(GMEM_DDESHARE, len(text.encode('utf-16-le')) + 2)
    pchData = d.kernel32.GlobalLock(hCd)
    ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
    d.kernel32.GlobalUnlock(hCd)
    d.user32.SetClipboardData(CF_UNICODETEXT, hCd)
    d.user32.CloseClipboard() 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:20,代码来源:pyperclip.py

示例8: _copyCygwin

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def _copyCygwin(text):
    GMEM_DDESHARE = 0x2000
    CF_UNICODETEXT = 13
    d = ctypes.cdll
    try:  # Python 2
        if not isinstance(text, unicode):
            text = text.decode('mbcs')
    except NameError:
        if not isinstance(text, str):
            text = text.decode('mbcs')
    d.user32.OpenClipboard(None)
    d.user32.EmptyClipboard()
    hCd = d.kernel32.GlobalAlloc(GMEM_DDESHARE, len(text.encode('utf-16-le')) + 2)
    pchData = d.kernel32.GlobalLock(hCd)
    ctypes.cdll.msvcrt.wcscpy(ctypes.c_wchar_p(pchData), text)
    d.kernel32.GlobalUnlock(hCd)
    d.user32.SetClipboardData(CF_UNICODETEXT, hCd)
    d.user32.CloseClipboard() 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:20,代码来源:pyperclip.py

示例9: _get_window_class

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def _get_window_class(hwnd):
  """Returns the class name of |hwnd|."""
  ctypes.windll.user32.GetClassNameW.restype = ctypes.c_int
  ctypes.windll.user32.GetClassNameW.argtypes = [
      ctypes.c_void_p,  # HWND
      ctypes.c_wchar_p,
      ctypes.c_int
  ]
  name = ctypes.create_unicode_buffer(257)
  name_len = ctypes.windll.user32.GetClassNameW(hwnd, name, len(name))
  if name_len <= 0 or name_len >= len(name):
    raise ctypes.WinError(descr='GetClassNameW failed; %s' %
                          ctypes.FormatError())
  return name.value


## Public API. 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:win.py

示例10: get_free_space

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def get_free_space(path):
  """Returns the number of free bytes.

  On POSIX platforms, this returns the free space as visible by the current
  user. On some systems, there's a percentage of the free space on the partition
  that is only accessible as the root user.
  """
  if sys.platform == 'win32':
    free_bytes = ctypes.c_ulonglong(0)
    windll.kernel32.GetDiskFreeSpaceExW(
        ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes))
    return free_bytes.value
  # For OSes other than Windows.
  f = fs.statvfs(path)  # pylint: disable=E1101
  return f.f_bfree * f.f_frsize


### Write file functions. 
开发者ID:luci,项目名称:luci-py,代码行数:20,代码来源:file_path.py

示例11: eval

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def eval(self, script, raw=False):
        """\
        Eval javascript string

        Examples:
            .eval("(()=>2)()") // (True, 2)
            .eval("(()=>a)()") // (False, "ReferenceError: 'a' is not defined")

        Parameters:
            script(str): javascript code string
            raw(bool?): whether return result as chakra JsValueRef directly
                        (optional, default is False)

        Returns:
            (bool, result)
            bool: indicates whether javascript is running successfully.
            result: if bool is True, result is the javascript running
                        return value.
                    if bool is False and result is string, result is the
                        javascript running exception
                    if bool is False and result is number, result is the
                        chakra internal error code
        """

        # TODO: may need a thread lock, if running multithreading
        self.__chakra.JsSetCurrentContext(self.__context)

        js_source = _ctypes.c_wchar_p("")
        js_script = _ctypes.c_wchar_p(script)

        result = _ctypes.c_void_p()
        err = self.__chakra.JsRunScript(js_script, 0, js_source, point(result))

        # no error
        if err == 0:
            if raw:
                return True, result
            else:
                return self.__js_value_to_py_value(result)

        return self.__get_error(err) 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:43,代码来源:jsengine_chakra.py

示例12: __js_value_to_str

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def __js_value_to_str(self, js_value):
        js_value_ref = _ctypes.c_void_p()
        self.__chakra.JsConvertValueToString(js_value, point(js_value_ref))

        str_p = _ctypes.c_wchar_p()
        str_l = _ctypes.c_size_t()
        self.__chakra.JsStringToPointer(js_value_ref, point(str_p), point(str_l))
        return str_p.value 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:10,代码来源:jsengine_chakra.py

示例13: KnownFolderPath

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def KnownFolderPath(guid):
        buf = ctypes.c_wchar_p()
        if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)):
            return None
        retval = buf.value	# copy data
        CoTaskMemFree(buf)	# and free original
        return retval 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:9,代码来源:config.py

示例14: QueryInfoKey

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def QueryInfoKey(key):
    """This calls the Windows RegQueryInfoKey function in a Unicode safe way."""
    null = LPDWORD()
    num_sub_keys = ctypes.wintypes.DWORD()
    num_values = ctypes.wintypes.DWORD()
    ft = FileTime()
    rc = RegQueryInfoKey(key.handle, ctypes.c_wchar_p(), null, null,
                         ctypes.byref(num_sub_keys), null, null,
                         ctypes.byref(num_values), null, null, null,
                                             ctypes.byref(ft))
    if rc != ERROR_SUCCESS:
        raise ctypes.WinError(2)

    return (num_sub_keys.value, num_values.value, ft.dwLowDateTime
                    | (ft.dwHighDateTime << 32)) 
开发者ID:google,项目名称:rekall,代码行数:17,代码来源:registry.py

示例15: EnumKey

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar_p [as 别名]
def EnumKey(key, index):
    """This calls the Windows RegEnumKeyEx function in a Unicode safe way."""
    buf = ctypes.create_unicode_buffer(257)
    length = ctypes.wintypes.DWORD(257)
    rc = RegEnumKeyEx(key.handle, index, ctypes.cast(buf, ctypes.c_wchar_p),
                      ctypes.byref(length), LPDWORD(), ctypes.c_wchar_p(),
                      LPDWORD(), ctypes.POINTER(FileTime)())
    if rc != 0:
        raise ctypes.WinError(2)

    return ctypes.wstring_at(buf, length.value).rstrip(u"\x00") 
开发者ID:google,项目名称:rekall,代码行数:13,代码来源:registry.py


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