Python ctypes.wintypes.WCHAR Examples

The following are 5 code examples of ctypes.wintypes.WCHAR(). 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.wintypes , or try the search function .
Example #1
Source File: evntprov.py    From pywintrace with Apache License 2.0 5 votes vote down vote up
def __init__(self, filter_in, events):
        struct_size = len(events) * ct.sizeof(wt.USHORT) + ct.sizeof(EVENT_FILTER_EVENT_ID)
        self._buf = (ct.c_char * struct_size)()
        self._props = ct.cast(ct.pointer(self._buf), ct.POINTER(EVENT_FILTER_EVENT_ID))
        self._props.contents.FilterIn = filter_in
        self._props.contents.Reserved = 0
        self._props.contents.Count = len(events)

        for i in range(len(events)):
            ct.memmove(ct.cast(ct.addressof(self._buf) + ct.sizeof(EVENT_FILTER_EVENT_ID) + (ct.sizeof(wt.WCHAR) * i),
                               ct.c_void_p),
                       ct.byref(wt.USHORT(events[i])),
                       ct.sizeof(wt.WCHAR)) 
Example #2
Source File: windows.py    From cloudbase-init with Apache License 2.0 5 votes vote down vote up
def _get_cch_referenced_domain_name(domain_name):
        return wintypes.DWORD(
            ctypes.sizeof(domain_name) // ctypes.sizeof(wintypes.WCHAR)) 
Example #3
Source File: platform_utils_win32.py    From git-repo with Apache License 2.0 5 votes vote down vote up
def PrintName(self):
    arrayt = WCHAR * (self.PrintNameLength // 2)
    offset = type(self).PathBuffer.offset + self.PrintNameOffset
    return arrayt.from_address(addressof(self) + offset).value 
Example #4
Source File: platform_utils_win32.py    From git-repo with Apache License 2.0 5 votes vote down vote up
def PrintName(self):
    arrayt = WCHAR * (self.PrintNameLength // 2)
    offset = type(self).PathBuffer.offset + self.PrintNameOffset
    return arrayt.from_address(addressof(self) + offset).value 
Example #5
Source File: vcp.py    From monitor_ctrl with MIT License 4 votes vote down vote up
def _get_physical_monitors_from_hmonitor(hmonitor: wintypes.HMONITOR) -> list:
    """
    Retrieves the physical monitors associated with an HMONITOR monitor handle

    https://msdn.microsoft.com/en-us/library/vs/alm/dd692950(v=vs.85).aspx
    BOOL GetPhysicalMonitorsFromHMONITOR(
        _In_   HMONITOR hMonitor,
        _In_   DWORD dwPhysicalMonitorArraySize,
        _Out_  LPPHYSICAL_MONITOR pPhysicalMonitorArray
    );
    
    Retrieves the number of physical monitors associated with an HMONITOR monitor handle.
    Call this function before calling GetPhysicalMonitorsFromHMONITOR.
    https://msdn.microsoft.com/en-us/library/dd692948(v=vs.85).aspx
    BOOL GetNumberOfPhysicalMonitorsFromHMONITOR(
        _In_   HMONITOR hMonitor,
        _Out_  LPDWORD pdwNumberOfPhysicalMonitors
    );

    :param hmonitor:
    :return:

    """
    class _PhysicalMonitorStructure(ctypes.Structure):
        """
        PHYSICAL_MONITOR Structure.
        https://msdn.microsoft.com/en-us/library/vs/alm/dd692967(v=vs.85).aspx
        typedef struct _PHYSICAL_MONITOR {
            HANDLE hPhysicalMonitor;
            WCHAR  szPhysicalMonitorDescription[PHYSICAL_MONITOR_DESCRIPTION_SIZE];
        } PHYSICAL_MONITOR, *LPPHYSICAL_MONITOR;

        PHYSICAL_MONITOR_DESCRIPTION_SIZE = 128
        """
        _fields_ = [
            ("hPhysicalMonitor", wintypes.HANDLE),
            ("szPhysicalMonitorDescription", wintypes.WCHAR * 128)
        ]

    # Retrieves the number of physical monitors
    phy_monitor_number = wintypes.DWORD()
    api_call_get_number = ctypes.windll.Dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR
    if not api_call_get_number(hmonitor, ctypes.byref(phy_monitor_number)):
        _LOGGER.error(ctypes.WinError())
        return []
    
    # Retrieves the physical monitors
    api_call_get_monitor = ctypes.windll.Dxva2.GetPhysicalMonitorsFromHMONITOR
    # create array
    phy_monitor_array = (_PhysicalMonitorStructure * phy_monitor_number.value)()
    if not api_call_get_monitor(hmonitor, phy_monitor_number, phy_monitor_array):
        _LOGGER.error(ctypes.WinError())
        return []
    
    return list(phy_monitor_array)