本文整理汇总了Python中ctypes.cdll方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.cdll方法的具体用法?Python ctypes.cdll怎么用?Python ctypes.cdll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.cdll方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_library
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def load_library(self, libname):
try:
result = LibraryLoader.load_library(self, libname)
except ImportError:
result = None
if os.path.sep not in libname:
for name in self.name_formats:
try:
result = getattr(ctypes.cdll, name % libname)
if result:
break
except WindowsError:
result = None
if result is None:
try:
result = getattr(ctypes.cdll, libname)
except WindowsError:
result = None
if result is None:
raise ImportError("%s not found." % libname)
return result
示例2: _copyWindows
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [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()
示例3: _copyCygwin
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [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()
示例4: on_parent_exit
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def on_parent_exit(signame):
"""
Return a function to be run in a child process which will trigger
SIGNAME to be sent when the parent process dies
"""
# On Windows, signal() can only be called with SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, or SIGTERM.
signum = getattr(signal, signame) # SIGTERM 15 SIGKILL 9
def set_parent_exit_signal():
# Constant taken from http://linux.die.net/include/linux/prctl.h
PR_SET_PDEATHSIG = 1
# http://linux.die.net/man/2/prctl
result = cdll['libc.so.6'].prctl(PR_SET_PDEATHSIG, signum)
if result != 0:
raise PrCtlError('prctl failed with error code %s' % result)
return set_parent_exit_signal
# https://stackoverflow.com/a/19448255/10517783
示例5: _copy_windows
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def _copy_windows(text, clear=0):
GMEM_DDESHARE = 0x2000
CF_UNICODETEXT = 13
d = ctypes.windll # cdll expects 4 more bytes in user32.OpenClipboard(0)
if not isinstance(text, unicode):
text = text.decode('mbcs')
d.user32.OpenClipboard(0 if is_python2() else 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()
示例6: statx
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def statx(fileno, path, flags, mask):
global _libc_statx
if not _libc_statx:
_libc_statx = ctypes.cdll[ctypes.util.find_library("c")]["statx"]
buf = struct_statx()
r = _libc_statx(ctypes.c_int(fileno),
ctypes.c_char_p(path.encode()),
ctypes.c_int(flags),
ctypes.c_uint(mask),
ctypes.byref(buf))
e = ctypes.get_errno()
# TODO: how do I make errno actually work and be non-zero
if r == 0:
return buf
else:
raise OSError(e, "statx failed for %r" % path)
示例7: load
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def load(self,path):
"""Given a path to a library, load it."""
try:
# Darwin requires dlopen to be called with mode RTLD_GLOBAL instead
# of the default RTLD_LOCAL. Without this, you end up with
# libraries not being loadable, resulting in "Symbol not found"
# errors
if sys.platform == 'darwin':
return ctypes.CDLL(path, ctypes.RTLD_GLOBAL)
else:
return ctypes.cdll.LoadLibrary(path)
except OSError as e:
raise ImportError(e)
示例8: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def __init__(self, path):
self.cdll = ctypes.cdll.LoadLibrary(path)
self.windll = ctypes.windll.LoadLibrary(path)
示例9: __getattr__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def __getattr__(self, name):
try: return getattr(self.cdll,name)
except AttributeError:
try: return getattr(self.windll,name)
except AttributeError:
raise
示例10: load_library
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def load_library(libname, loader_path):
if ctypes.__version__ < '1.0.1':
import warnings
warnings.warn("All features of ctypes interface may not work " \
"with ctypes < 1.0.1")
ext = os.path.splitext(libname)[1]
if not ext:
# Try to load library with platform-specific name, otherwise
# default to libname.[so|pyd]. Sometimes, these files are built
# erroneously on non-linux platforms.
from numpy.distutils.misc_util import get_shared_lib_extension
so_ext = get_shared_lib_extension()
libname_ext = [libname + so_ext]
# mac, windows and linux >= py3.2 shared library and loadable
# module have different extensions so try both
so_ext2 = get_shared_lib_extension(is_python_ext=True)
if not so_ext2 == so_ext:
libname_ext.insert(0, libname + so_ext2)
else:
libname_ext = [libname]
loader_path = os.path.abspath(loader_path)
if not os.path.isdir(loader_path):
libdir = os.path.dirname(loader_path)
else:
libdir = loader_path
for ln in libname_ext:
libpath = os.path.join(libdir, ln)
if os.path.exists(libpath):
try:
return ctypes.cdll[libpath]
except OSError:
## defective lib file
raise
## if no successful return in the libname_ext loop:
raise OSError("no file with expected extension")
示例11: load
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def load(self,path):
"""Given a path to a library, load it."""
try:
# Darwin requires dlopen to be called with mode RTLD_GLOBAL instead
# of the default RTLD_LOCAL. Without this, you end up with
# libraries not being loadable, resulting in "Symbol not found"
# errors
if sys.platform == 'darwin':
return ctypes.CDLL(path, ctypes.RTLD_GLOBAL)
else:
return ctypes.cdll.LoadLibrary(path)
except OSError,e:
raise ImportError(e)
示例12: _pasteCygwin
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import cdll [as 别名]
def _pasteCygwin():
CF_UNICODETEXT = 13
d = ctypes.cdll
d.user32.OpenClipboard(None)
handle = d.user32.GetClipboardData(CF_UNICODETEXT)
data = ctypes.c_wchar_p(handle).value
d.user32.CloseClipboard()
return data