Python ctypes.windll.LoadLibrary() Examples

The following are 7 code examples of ctypes.windll.LoadLibrary(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ctypes.windll , or try the search function .
Example #1
Source File: test_win32_shim.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_handler(self):
        @count_calls
        def interrupt_polling():
            print('Caught CTRL-C!')

        from ctypes import windll
        from ctypes.wintypes import BOOL, DWORD

        kernel32 = windll.LoadLibrary('kernel32')

        # <http://msdn.microsoft.com/en-us/library/ms683155.aspx>
        GenerateConsoleCtrlEvent = kernel32.GenerateConsoleCtrlEvent
        GenerateConsoleCtrlEvent.argtypes = (DWORD, DWORD)
        GenerateConsoleCtrlEvent.restype = BOOL

        # Simulate CTRL-C event while handler is active.
        try:
            with allow_interrupt(interrupt_polling) as context:
                result = GenerateConsoleCtrlEvent(0, 0)
                # Sleep so that we give time to the handler to
                # capture the Ctrl-C event.
                time.sleep(0.5)
        except KeyboardInterrupt:
            pass
        else:
            if result == 0:
                raise WindowsError()
            else:
                self.fail('Expecting `KeyboardInterrupt` exception!')

        # Make sure our handler was called.
        self.assertEqual(interrupt_polling.__calls__, 1) 
Example #2
Source File: ctypes.py    From pyclibrary with MIT License 5 votes vote down vote up
def _link_library(self, lib_path, convention):
        """Find and link the external librairy if only a path was provided.

        """
        if convention == 'cdll':
            return cdll.LoadLibrary(lib_path)
        elif convention == 'windll':
            return windll.LoadLibrary(lib_path)
        elif convention == 'oledll':
            return oledll.LoadLibrary(lib_path)
        else:
            raise ValueError('Convention cannot be {}'.format(convention)) 
Example #3
Source File: test_win32_shim.py    From pySINDy with MIT License 5 votes vote down vote up
def test_handler(self):
        @count_calls
        def interrupt_polling():
            print('Caught CTRL-C!')

        from ctypes import windll
        from ctypes.wintypes import BOOL, DWORD

        kernel32 = windll.LoadLibrary('kernel32')

        # <http://msdn.microsoft.com/en-us/library/ms683155.aspx>
        GenerateConsoleCtrlEvent = kernel32.GenerateConsoleCtrlEvent
        GenerateConsoleCtrlEvent.argtypes = (DWORD, DWORD)
        GenerateConsoleCtrlEvent.restype = BOOL

        # Simulate CTRL-C event while handler is active.
        try:
            with allow_interrupt(interrupt_polling) as context:
                result = GenerateConsoleCtrlEvent(0, 0)
                # Sleep so that we give time to the handler to
                # capture the Ctrl-C event.
                time.sleep(0.5)
        except KeyboardInterrupt:
            pass
        else:
            if result == 0:
                raise WindowsError()
            else:
                self.fail('Expecting `KeyboardInterrupt` exception!')

        # Make sure our handler was called.
        self.assertEqual(interrupt_polling.__calls__, 1) 
Example #4
Source File: phandle_dll.py    From pypykatz with MIT License 5 votes vote down vote up
def get_lsass_handle():
	your_dll = windll.LoadLibrary(dll_path)
	_your_function = your_dll.your_function
	_your_function.argtypes = [] #I guess no args
	_your_function.restype  = c_void_p #this is basically a handle
	
	phandle = _your_function()

	return phandle 
Example #5
Source File: ddeclient.py    From pymt5 with MIT License 5 votes vote down vote up
def get_winfunc(libname, funcname, restype=None, argtypes=(), _libcache={}):
    """Retrieve a function from a library/DLL, and set the data types."""
    if libname not in _libcache:
        _libcache[libname] = windll.LoadLibrary(libname)
    func = getattr(_libcache[libname], funcname)
    func.argtypes = argtypes
    func.restype = restype
    return func 
Example #6
Source File: dde.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def get_winfunc(libname, funcname, restype=None, argtypes=(), _libcache={}):
    """Retrieve a function from a library, and set the data types."""
    from ctypes import windll

    if libname not in _libcache:
        _libcache[libname] = windll.LoadLibrary(libname)
    func = getattr(_libcache[libname], funcname)
    func.argtypes = argtypes
    func.restype = restype

    return func 
Example #7
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def __start__(self):
        self.dll = None
        try:
            self.dll = windll.LoadLibrary("TellUsbD101.dll")
        except:
            raise eg.Exception("TellUsbD101.dll not found.")