當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。