本文整理汇总了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.")
示例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
示例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()
示例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)
示例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()
示例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.
示例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()
示例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()
示例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.
示例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.
示例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)
示例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
示例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
示例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))
示例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")