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


Python ctypes.wintypes方法代码示例

本文整理汇总了Python中ctypes.wintypes方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.wintypes方法的具体用法?Python ctypes.wintypes怎么用?Python ctypes.wintypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.wintypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _is_gui_available

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def _is_gui_available():
        UOI_FLAGS = 1
        WSF_VISIBLE = 0x0001
        class USEROBJECTFLAGS(ctypes.Structure):
            _fields_ = [("fInherit", ctypes.wintypes.BOOL),
                        ("fReserved", ctypes.wintypes.BOOL),
                        ("dwFlags", ctypes.wintypes.DWORD)]
        dll = ctypes.windll.user32
        h = dll.GetProcessWindowStation()
        if not h:
            raise ctypes.WinError()
        uof = USEROBJECTFLAGS()
        needed = ctypes.wintypes.DWORD()
        res = dll.GetUserObjectInformationW(h,
            UOI_FLAGS,
            ctypes.byref(uof),
            ctypes.sizeof(uof),
            ctypes.byref(needed))
        if not res:
            raise ctypes.WinError()
        return bool(uof.dwFlags & WSF_VISIBLE) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:23,代码来源:support.py

示例2: get_window_thread_process_id

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def get_window_thread_process_id(window_obj):
    """A nice wrapper for GetWindowThreadProcessId(). Returns a tuple of the
    thread id (tid) of the thread that created the specified window, and the
    process id that created the window.

    Syntax:
    DWORD GetWindowThreadProcessId(
      HWND    hWnd,
      LPDWORD lpdwProcessId
    );

    Microsoft Documentation:
    https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowthreadprocessid
    """
    pid = wintypes.DWORD()
    tid = ctypes.windll.user32.GetWindowThreadProcessId(window_obj.hWnd, ctypes.byref(pid))
    return tid, pid.value 
开发者ID:asweigart,项目名称:nicewin,代码行数:19,代码来源:__init__.py

示例3: _create_windows

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def _create_windows(source, destination, link_type):
    """Creates hardlink at destination from source in Windows."""

    if link_type == HARDLINK:
        import ctypes
        from ctypes.wintypes import BOOL
        CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW
        CreateHardLink.argtypes = [
            ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_void_p
        ]
        CreateHardLink.restype = BOOL

        res = CreateHardLink(destination, source, None)
        if res == 0:
            raise ctypes.WinError()
    else:
        raise NotImplementedError("Link type unrecognized.") 
开发者ID:getavalon,项目名称:core,代码行数:19,代码来源:link.py

示例4: open_device

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def open_device(self, access=GENERIC_READ | GENERIC_WRITE, mode=0, creation=OPEN_EXISTING, flags=FILE_ATTRIBUTE_NORMAL):
        """See: CreateFile function
        http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
        """
        CreateFile_Fn = ctypes.windll.kernel32.CreateFileA
        CreateFile_Fn.argtypes = [
                wintypes.LPCSTR,                    # _In_          LPCTSTR lpFileName
                wintypes.DWORD,                     # _In_          DWORD dwDesiredAccess
                wintypes.DWORD,                     # _In_          DWORD dwShareMode
                LPSECURITY_ATTRIBUTES,              # _In_opt_      LPSECURITY_ATTRIBUTES lpSecurityAttributes
                wintypes.DWORD,                     # _In_          DWORD dwCreationDisposition
                wintypes.DWORD,                     # _In_          DWORD dwFlagsAndAttributes
                wintypes.HANDLE]                    # _In_opt_      HANDLE hTemplateFile
        CreateFile_Fn.restype = wintypes.HANDLE

        
        self.handle = wintypes.HANDLE(CreateFile_Fn('\\\\.\\' + self.name,
                             access,
                             mode,
                             NULL,
                             creation,
                             flags,
                             NULL)) 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:25,代码来源:driverlib.py

示例5: open_service

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def open_service(service_manager_handle, service_name, desired_access):
	""" See: OpenService function
	https://msdn.microsoft.com/en-us/library/windows/desktop/ms684330(v=vs.85).aspx
	"""
	OpenService_Fn = ctypes.windll.Advapi32.OpenServiceA 	#SC_HANDLE WINAPI OpenService(
	OpenService_Fn.argtypes = [						#
		wintypes.HANDLE,							#	_In_ SC_HANDLE hSCManager,
		LPCTSTR,							#	_In_ LPCTSTR   lpServiceName,
		wintypes.DWORD								#	_In_ DWORD     dwDesiredAccess
	]
	OpenService_Fn.restype = wintypes.SC_HANDLE
	handle = OpenService_Fn(
		service_manager_handle,
		service_name,
		desired_access
	)
	return handle 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:19,代码来源:driverlib.py

示例6: open_sc_manager

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def open_sc_manager(machine_name, database_name, desired_access):
	"""See: OpenSCManager function
	https://msdn.microsoft.com/en-us/library/windows/desktop/ms684323(v=vs.85).aspx
	"""
	OpenSCManager_Fn = ctypes.windll.Advapi32.OpenSCManagerA	#SC_HANDLE WINAPI OpenSCManager(
	OpenSCManager_Fn.argtypes = [						#
		LPCTSTR,								#	_In_opt_ LPCTSTR lpMachineName,
		LPCTSTR,								#	_In_opt_ LPCTSTR lpDatabaseName,
		wintypes.DWORD									#	_In_     DWORD   dwDesiredAccess
	]
	OpenSCManager_Fn.restype = wintypes.SC_HANDLE
	handle = OpenSCManager_Fn(
		machine_name,
		database_name,
		desired_access
	)
	return handle 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:19,代码来源:driverlib.py

示例7: start_service

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def start_service(service_handle, service_arg_count, service_arg_vectors):
	"""See: StartService function
	https://msdn.microsoft.com/en-us/library/windows/desktop/ms686321(v=vs.85).aspx
	"""
	
	StartService_Fn = ctypes.windll.Advapi32.StartServiceA	#BOOL WINAPI StartService(
	StartService_Fn.argtypes = [					#
		wintypes.SC_HANDLE,							#	_In_ 	 SC_HANDLE hService,
		wintypes.DWORD,								#	_In_ 	 DWORD     dwNumServiceArgs,
		LPCTSTR							#	_In_opt_ LPCTSTR   *lpServiceArgVectors
	]
	StartService_Fn.restype = wintypes.BOOL
	bool = StartService_Fn(
		service_handle,
		service_arg_count, 
		service_arg_vectors
	)
	return bool 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:20,代码来源:driverlib.py

示例8: QueryValueEx

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def QueryValueEx(key, value_name):
    """This calls the Windows QueryValueEx function in a Unicode safe way."""
    size = 256
    data_type = ctypes.wintypes.DWORD()
    while True:
        tmp_size = ctypes.wintypes.DWORD(size)
        buf = ctypes.create_string_buffer(size)
        rc = RegQueryValueEx(key.handle, value_name, LPDWORD(),
                             ctypes.byref(data_type), ctypes.cast(buf, LPBYTE),
                             ctypes.byref(tmp_size))
        if rc != ERROR_MORE_DATA:
            break

        # We limit the size here to ~10 MB so the response doesn't get too big.
        if size > 10 * 1024 * 1024:
            raise WindowsError("Value too big to be read.")

        size *= 2

    if rc != ERROR_SUCCESS:
        raise ctypes.WinError(2)

    return (Reg2Py(buf, tmp_size.value, data_type.value), data_type.value) 
开发者ID:google,项目名称:rekall,代码行数:25,代码来源:registry.py

示例9: PerformStandardReset

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def PerformStandardReset(self):
        self.Connect()
        self.ResetToggle()
        self.NominalModeToggle()
        self.Disconnect()
        return True

        def SetResetHigh(self):
                ##RESET HIGH TEST LOW
                self.ftd2xxDll.FT_SetBitMode(self.handle, self.BITMASK_IO_OUTPUTS | self.BITMASK_RST, 0x20)

#Action
#BslMode()
#NominalMode()
#NominalForced()
#DisableBsl()

#writeBuffer = ctypes.create_string_buffer("abcdefghijklmnopqrstuvwxyz")
#bytesWritten = ctypes.wintypes.DWORD()
#assert self.ftd2xxDll.FT_Write(self.handle, writeBuffer, len(writeBuffer)-1, ctypes.byref(bytesWritten)) == 0
#print bytesWritten.value 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:23,代码来源:faradayftdi.py

示例10: _formatMessage

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def _formatMessage(errorCode):
    """A nice wrapper for FormatMessageW(). TODO

    Microsoft Documentation:
    https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-formatmessagew

    Additional information:
    https://stackoverflow.com/questions/18905702/python-ctypes-and-mutable-buffers
    https://stackoverflow.com/questions/455434/how-should-i-use-formatmessage-properly-in-c
    """
    lpBuffer = wintypes.LPWSTR()

    ctypes.windll.kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
                                          NULL,
                                          errorCode,
                                          0, # dwLanguageId
                                          ctypes.cast(ctypes.byref(lpBuffer), wintypes.LPWSTR),
                                          0, # nSize
                                          NULL)
    msg = lpBuffer.value.rstrip()
    ctypes.windll.kernel32.LocalFree(lpBuffer) # Free the memory allocated for the error message's buffer.
    return msg 
开发者ID:asweigart,项目名称:PyGetWindow,代码行数:24,代码来源:_pygetwindow_win.py

示例11: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def __init__(self) -> None:
        super().__init__()
        # ANSI handling available through SetConsoleMode since Windows 10 v1511
        # https://en.wikipedia.org/wiki/ANSI_escape_code#cite_note-win10th2-1
        if platform.release() == '10' and int(platform.version().split('.')[2]) > 10586:
            ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
            import ctypes.wintypes as wintypes
            if not hasattr(wintypes, 'LPDWORD'):  # PY2
                wintypes.LPDWORD = ctypes.POINTER(wintypes.DWORD)
            SetConsoleMode = ctypes.windll.kernel32.SetConsoleMode
            GetConsoleMode = ctypes.windll.kernel32.GetConsoleMode
            GetStdHandle = ctypes.windll.kernel32.GetStdHandle
            mode = wintypes.DWORD()
            GetConsoleMode(GetStdHandle(-11), ctypes.byref(mode))
            if (mode.value & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0:
                SetConsoleMode(GetStdHandle(-11), mode.value | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
                self._saved_cm = mode 
开发者ID:vlasovskikh,项目名称:intellij-micropython,代码行数:19,代码来源:microrepl.py

示例12: Initialize

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def Initialize(self, application_name):
        """
        Function to call DirectOutput_Initialize
        
        Required Arguments:
        application_name -- String representing name of applicaiton - must be unique per-application
        
        Returns:
        S_OK: The call completed sucesfully
        E_OUTOFMEMORY: There was insufficient memory to complete this call.
        E_INVALIDARG: The argument is invalid
        E_HANDLE: The DirectOutputManager process could not be found
        
        """
        logging.debug("DirectOutput.Initialize")
        return self.DirectOutputDLL.DirectOutput_Initialize(ctypes.wintypes.LPWSTR(application_name)) 
开发者ID:eyeonus,项目名称:Trade-Dangerous,代码行数:18,代码来源:directoutput.py

示例13: SetString

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def SetString(self, device_handle, page, line, string):
        """
        Sets a string to display on the MFD
        
        Required Arguments:
        device_handle -- ID of device
        page -- the ID of the page to add the string to
        line -- the line to display the string on (0 = top, 1 = middle, 2 = bottom)
        string -- the string to display
        
        Returns:
        S_OK: The call completes successfully.
        E_INVALIDARG: The dwPage argument does not reference a valid page id, or the dwString argument does not reference a valid string id.
        E_OUTOFMEMORY: Insufficient memory to complete the request.
        E_HANDLE: The device handle specified is invalid.
        
        """
        logging.debug("DirectOutput.SetString({}, {}, {}, {})".format(device_handle, page, line, string))
        return self.DirectOutputDLL.DirectOutput_SetString(device_handle, page, line, len(string), ctypes.wintypes.LPWSTR(string)) 
开发者ID:eyeonus,项目名称:Trade-Dangerous,代码行数:21,代码来源:directoutput.py

示例14: get_root

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def get_root(key: list =['网上股票交易系统', '通达信']) -> tuple:
    from ctypes.wintypes import BOOL, HWND, LPARAM

    @ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
    def callback(hwnd, lparam):
        user32.GetWindowTextW(hwnd, buf, 64)
        for s in key:
            if s in buf.value:
                handle.value = hwnd
                return False
        return True

    buf = ctypes.create_unicode_buffer(64)
    handle = ctypes.c_ulong()
    user32.EnumWindows(callback)
    return handle.value, buf.value 
开发者ID:Raytone-D,项目名称:puppet,代码行数:18,代码来源:puppet_util.py

示例15: getWindowsShortPath

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import wintypes [as 别名]
def getWindowsShortPath(path):
    try:
        import ctypes
        import ctypes.wintypes

        ctypes.windll.kernel32.GetShortPathNameW.argtypes = [
            ctypes.wintypes.LPCWSTR,  # lpszLongPath
            ctypes.wintypes.LPWSTR,  # lpszShortPath
            ctypes.wintypes.DWORD  # cchBuffer
        ]
        ctypes.windll.kernel32.GetShortPathNameW.restype = ctypes.wintypes.DWORD

        buf = ctypes.create_unicode_buffer(1024)  # adjust buffer size, if necessary
        ctypes.windll.kernel32.GetShortPathNameW(path, buf, len(buf))

        return buf.value
    except:
        return path 
开发者ID:alfa-addon,项目名称:addon,代码行数:20,代码来源:util.py


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