Python ctypes.windll.LoadLibrary() Examples

The following are 7 code examples for showing how to use ctypes.windll.LoadLibrary(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module ctypes.windll , or try the search function .

Example 1
Project: vnpy_crypto   Author: birforce   File: test_win32_shim.py    License: 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
Project: pyclibrary   Author: MatthieuDartiailh   File: ctypes.py    License: 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
Project: pySINDy   Author: luckystarufo   File: test_win32_shim.py    License: 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
Project: pypykatz   Author: skelsec   File: phandle_dll.py    License: 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
Project: pymt5   Author: devcartel   File: ddeclient.py    License: 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
Project: EventGhost   Author: EventGhost   File: dde.py    License: 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
Project: EventGhost   Author: EventGhost   File: __init__.py    License: 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.")