本文整理匯總了Python中ctypes.WinDLL方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.WinDLL方法的具體用法?Python ctypes.WinDLL怎麽用?Python ctypes.WinDLL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes.WinDLL方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _load
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def _load(self):
library_path = find_library(self.name)
if library_path is None:
env_var_name = "PATH" if sys.platform == 'win32' else "LD_LIBRARY_PATH"
raise CannotFindPicoSDKError("PicoSDK (%s) not found, check %s" % (self.name, env_var_name))
try:
if sys.platform == 'win32':
from ctypes import WinDLL
result = WinDLL(library_path)
else:
from ctypes import cdll
result = cdll.LoadLibrary(library_path)
except OSError as e:
raise CannotOpenPicoSDKError("PicoSDK (%s) not compatible (check 32 vs 64-bit): %s" % (self.name, e))
return result
示例2: command_detach
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def command_detach(self):
detach_threads()
# unload debugger DLL
global debugger_dll_handle
if debugger_dll_handle is not None:
k32 = ctypes.WinDLL('kernel32')
k32.FreeLibrary.argtypes = [ctypes.c_void_p]
k32.FreeLibrary(debugger_dll_handle)
debugger_dll_handle = None
with _SendLockCtx:
write_bytes(conn, DETC)
detach_process()
for callback in DETACH_CALLBACKS:
callback()
raise DebuggerExitException()
示例3: checkFirmwareType
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [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.
示例4: __loaddll
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def __loaddll(self, fp=None):
if fp != None:
if os.path.exists(fp):
self.nnotesdll = ctypes.WinDLL(fp)
else:
self.nnotesdll = None
else:
self.nnotesdll = None
try:
# If we already have the COM/DDE interface to Notes, then nlsxbe.dll
# is already loaded, so we can just try and get nnotes.dll leaving
# Windows to search in its default search path
self.nnotesdll = ctypes.WinDLL('nnotes.dll')
except OSError:
# Try harder
for p in notesDllPathList:
fp = os.path.join(p, 'nnotes.dll')
if os.path.exists(fp):
self.nnotesdll = ctypes.WinDLL(fp)
break
示例5: psloadlib
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def psloadlib(name):
""" Loads driver library
:param name: driver name
:type name: str
:returns: ctypes reference to the library
:rtype: object
"""
result = None
try:
if sys.platform == 'win32':
result = ctypes.WinDLL(find_library(name))
else:
result = cdll.LoadLibrary(find_library(name))
except OSError as ex:
print name, "import(%d): Library not found" % sys.exc_info()[-1].tb_lineno
return result
示例6: __init__
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def __init__(self):
# Load DLL into memory.
self.interceptionDll = ctypes.WinDLL ("./lib/interception.dll")
# Setup return types
self.interceptionDll.interception_create_context.restype = InterceptionContext_p
self.interceptionDll.interception_get_filter.restype = InterceptionFilter
self.interceptionDll.interception_get_precedence.restype = InterceptionPrecedence
self.interceptionDll.interception_wait.restype = InterceptionDevice
self.interceptionDll.interception_wait_with_timeout.restype = InterceptionDevice
self.interceptionDll.interception_is_invalid.restype = ctypes.c_int
self.interceptionDll.interception_is_keyboard.restype = ctypes.c_int
self.interceptionDll.interception_is_mouse.restype = ctypes.c_int
self.interceptionDll.interception_send.restype = ctypes.c_int
self.interceptionDll.interception_receive.restype = ctypes.c_int
self.interceptionDll.interception_get_hardware_id.restype = ctypes.c_uint
#Setup callback functions (that actually call the dll again)
funct_type = ctypes.WINFUNCTYPE(ctypes.c_int,InterceptionDevice)
self.interception_is_invalid = funct_type(self.__interception_is_invalid)
self.interception_is_keyboard = funct_type(self.__interception_is_keyboard)
self.interception_is_mouse = funct_type(self.__interception_is_mouse)
示例7: get_keyboard_language
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def get_keyboard_language():
# https://stackoverflow.com/a/42047820/261181
if platform.system() != "Windows":
raise NotImplementedError("Can provide keyboard language only on Windows")
import ctypes
user32 = ctypes.WinDLL("user32", use_last_error=True)
curr_window = user32.GetForegroundWindow()
thread_id = user32.GetWindowThreadProcessId(curr_window, 0)
# Made up of 0xAAABBBB, AAA = HKL (handle object) & BBBB = language ID
klid = user32.GetKeyboardLayout(thread_id)
# Language ID -> low 10 bits, Sub-language ID -> high 6 bits
# Extract language ID from KLID
lid = klid & (2 ** 16 - 1)
return lid
示例8: remove_ca
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def remove_ca(self, name):
import ctypes
import ctypes.wintypes
class CERT_CONTEXT(ctypes.Structure):
_fields_ = [
('dwCertEncodingType', ctypes.wintypes.DWORD),
('pbCertEncoded', ctypes.POINTER(ctypes.wintypes.BYTE)),
('cbCertEncoded', ctypes.wintypes.DWORD),
('pCertInfo', ctypes.c_void_p),
('hCertStore', ctypes.c_void_p),]
crypt32 = ctypes.WinDLL(b'crypt32.dll'.decode())
store_handle = crypt32.CertOpenStore(10, 0, 0, 0x4000 | 0x20000, b'ROOT'.decode())
pCertCtx = crypt32.CertEnumCertificatesInStore(store_handle, None)
while pCertCtx:
certCtx = CERT_CONTEXT.from_address(pCertCtx)
certdata = ctypes.string_at(certCtx.pbCertEncoded, certCtx.cbCertEncoded)
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certdata)
if hasattr(cert, 'get_subject'):
cert = cert.get_subject()
cert_name = next((v for k, v in cert.get_components() if k == 'CN'), '')
if cert_name and name.lower() == cert_name.split()[0].lower():
crypt32.CertDeleteCertificateFromStore(crypt32.CertDuplicateCertificateContext(pCertCtx))
pCertCtx = crypt32.CertEnumCertificatesInStore(store_handle, pCertCtx)
return 0
示例9: init
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def init():
"""
Initializes the ntfsea library.
"""
if ntfsea.lib is None:
if hasattr(ctypes, 'WinDLL'):
loader = ctypes.WinDLL
else:
loader = ctypes.CDLL
ntfsea.lib = loader('ntfsea_%s.dll' % ('x64' if platform.architecture()[0] == '64bit' else 'x86'))
ntfsea.lib.GetEaList.restype = ctypes.POINTER(ntfsea_EaList)
ntfsea.lib.GetEa.restype = ctypes.POINTER(ntfsea_Ea)
ntfsea.lib.WriteEa.restype = ctypes.c_int
示例10: __init__
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def __init__(self, tzres_loc='tzres.dll'):
# Load the user32 DLL so we can load strings from tzres
user32 = ctypes.WinDLL('user32')
# Specify the LoadStringW function
user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
wintypes.UINT,
wintypes.LPWSTR,
ctypes.c_int)
self.LoadStringW = user32.LoadStringW
self._tzres = ctypes.WinDLL(tzres_loc)
self.tzres_loc = tzres_loc
示例11: displaypath
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def displaypath(self, pathvar, entryfield):
entryfield['state'] = tk.NORMAL # must be writable to update
entryfield.delete(0, tk.END)
if platform=='win32':
start = pathvar.get().lower().startswith(config.home.lower()) and len(config.home.split('\\')) or 0
display = []
components = normpath(pathvar.get()).split('\\')
buf = ctypes.create_unicode_buffer(MAX_PATH)
pidsRes = ctypes.c_int()
for i in range(start, len(components)):
try:
if (not SHGetLocalizedName('\\'.join(components[:i+1]), buf, MAX_PATH, ctypes.byref(pidsRes)) and
LoadString(ctypes.WinDLL(expandvars(buf.value))._handle, pidsRes.value, buf, MAX_PATH)):
display.append(buf.value)
else:
display.append(components[i])
except:
display.append(components[i])
entryfield.insert(0, '\\'.join(display))
elif platform=='darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()): # None if path doesn't exist
if pathvar.get().startswith(config.home):
display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)):]
else:
display = NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())
entryfield.insert(0, '/'.join(display))
else:
if pathvar.get().startswith(config.home):
entryfield.insert(0, '~' + pathvar.get()[len(config.home):])
else:
entryfield.insert(0, pathvar.get())
entryfield['state'] = 'readonly'
示例12: lib
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def lib(self):
"""Returns the reference to the loaded library object.
For example, if `libtype` is
* ``'cdll'`` then a :class:`~ctypes.CDLL` object
* ``'windll'`` then a :class:`~ctypes.WinDLL` object
* ``'oledll'`` then a :class:`~ctypes.OleDLL` object
* ``'net'`` or ``'clr'`` then a :class:`~.load_library.DotNet` object
* ``'java'`` then a :class:`~py4j.java_gateway.JVMView` object
* ``'com'`` then the interface pointer returned by comtypes.CreateObject_
"""
return self._lib
示例13: __init__
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def __init__(self, tzres_loc='tzres.dll'):
# Load the user32 DLL so we can load strings from tzres
user32 = ctypes.WinDLL('user32')
# Specify the LoadStringW function
user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
wintypes.UINT,
wintypes.LPWSTR,
ctypes.c_int)
self.LoadStringW = user32.LoadStringW
self._tzres = ctypes.WinDLL(tzres_loc)
self.tzres_loc = tzres_loc
示例14: copyload_shared_lib
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def copyload_shared_lib(dst_prefix=TESTFILE_PREFIX):
"""Ctx manager which picks up a random shared DLL lib used
by this process, copies it in another location and loads it
in memory via ctypes.
Return the new absolutized, normcased path.
"""
from ctypes import wintypes
from ctypes import WinError
ext = ".dll"
dst = tempfile.mktemp(prefix=dst_prefix, suffix=ext)
libs = [x.path for x in psutil.Process().memory_maps() if
os.path.splitext(x.path)[1].lower() == ext and
'python' in os.path.basename(x.path).lower() and
'wow64' not in x.path.lower()]
src = random.choice(libs)
shutil.copyfile(src, dst)
cfile = None
try:
cfile = ctypes.WinDLL(dst)
yield dst
finally:
# Work around OverflowError:
# - https://ci.appveyor.com/project/giampaolo/psutil/build/1207/
# job/o53330pbnri9bcw7
# - http://bugs.python.org/issue30286
# - http://stackoverflow.com/questions/23522055
if cfile is not None:
FreeLibrary = ctypes.windll.kernel32.FreeLibrary
FreeLibrary.argtypes = [wintypes.HMODULE]
ret = FreeLibrary(cfile._handle)
if ret == 0:
WinError()
safe_rmpath(dst)
示例15: are_long_paths_enabled
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import WinDLL [as 別名]
def are_long_paths_enabled():
if os_name == "Windows":
from ctypes import WinDLL, c_ubyte
ntdll = WinDLL('ntdll')
if hasattr(ntdll, 'RtlAreLongPathsEnabled'):
ntdll.RtlAreLongPathsEnabled.restype = c_ubyte
ntdll.RtlAreLongPathsEnabled.argtypes = ()
return bool(ntdll.RtlAreLongPathsEnabled())
else:
return False