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


Python ctypes.WinDLL方法代码示例

本文整理汇总了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 
开发者ID:picotech,项目名称:picosdk-python-wrappers,代码行数:19,代码来源:library.py

示例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() 
开发者ID:ms-iot,项目名称:iot-utilities,代码行数:21,代码来源:visualstudio_py_debugger.py

示例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. 
开发者ID:nsacyber,项目名称:Splunk-Assessment-of-Mitigation-Implementations,代码行数:25,代码来源:ae.py

示例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 
开发者ID:adb014,项目名称:nsf2x,代码行数:22,代码来源:nsf2x.py

示例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 
开发者ID:picotech,项目名称:picosdk-python-examples,代码行数:18,代码来源:psutils.py

示例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) 
开发者ID:maaaxim,项目名称:bot,代码行数:25,代码来源:InterceptionWrapper.py

示例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 
开发者ID:thonny,项目名称:thonny,代码行数:19,代码来源:tktextext.py

示例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 
开发者ID:projectarkc,项目名称:arkc-client,代码行数:26,代码来源:proxylib.py

示例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 
开发者ID:RoliSoft,项目名称:WSL-Distribution-Switcher,代码行数:17,代码来源:ntfsea.py

示例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 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:15,代码来源:win.py

示例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' 
开发者ID:EDCD,项目名称:EDMarketConnector,代码行数:33,代码来源:prefs.py

示例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 
开发者ID:MSLNZ,项目名称:msl-loadlib,代码行数:15,代码来源:load_library.py

示例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 
开发者ID:skarlekar,项目名称:faces,代码行数:15,代码来源:win.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:35,代码来源:__init__.py

示例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 
开发者ID:DIGITALCRIMINAL,项目名称:OnlyFans,代码行数:15,代码来源:main_helper.py


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