1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
# Copyright 2017 Cloudbase Solutions Srl
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# This module contains some common types extracted from ctypes.wintypes
# plus some extra ones that we are using throughout os-win.
#
# In order to avoid portability issues more easily, we avoid using
# ctypes.wintypes directly.
import ctypes
import sys
import uuid
BYTE = ctypes.c_byte
WORD = ctypes.c_ushort
DWORD = ctypes.c_ulong
CHAR = ctypes.c_char
WCHAR = ctypes.c_wchar
UINT = ctypes.c_uint
INT = ctypes.c_int
DOUBLE = ctypes.c_double
FLOAT = ctypes.c_float
BOOLEAN = BYTE
BOOL = ctypes.c_long
ULONG = ctypes.c_ulong
LONG = ctypes.c_long
USHORT = ctypes.c_ushort
SHORT = ctypes.c_short
LONGLONG = _LARGE_INTEGER = LARGE_INTEGER = ctypes.c_longlong
ULONGLONG = _ULARGE_INTEGER = ULARGE_INTEGER = ctypes.c_ulonglong
LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p
LPCWSTR = LPWSTR = PWSTR = ctypes.c_wchar_p
LPCSTR = LPSTR = PSTR = ctypes.c_char_p
LPCVOID = LPVOID = PVOID = ctypes.c_void_p
HANDLE = ctypes.c_void_p
LPBOOL = PBOOL = ctypes.POINTER(BOOL)
PBOOLEAN = ctypes.POINTER(BOOLEAN)
LPBYTE = PBYTE = ctypes.POINTER(BYTE)
PCHAR = ctypes.POINTER(CHAR)
LPDWORD = PDWORD = ctypes.POINTER(DWORD)
PFLOAT = ctypes.POINTER(FLOAT)
LPHANDLE = PHANDLE = ctypes.POINTER(HANDLE)
LPINT = PINT = ctypes.POINTER(INT)
PLARGE_INTEGER = ctypes.POINTER(LARGE_INTEGER)
LPLONG = PLONG = ctypes.POINTER(LONG)
PLONGLONG = ctypes.POINTER(LONGLONG)
PSHORT = ctypes.POINTER(SHORT)
LPUINT = PUINT = ctypes.POINTER(UINT)
PULARGE_INTEGER = ctypes.POINTER(ULARGE_INTEGER)
PULONG = ctypes.POINTER(ULONG)
PUSHORT = ctypes.POINTER(USHORT)
# Warning: PWCHAR behaves differently than c_wchar_p. Accessing
# a PWCHAR structure attribute won't give us back a Python string.
PWCHAR = ctypes.POINTER(WCHAR)
LPWORD = PWORD = ctypes.POINTER(WORD)
class GUID(ctypes.Structure):
_fields_ = [
("Data1", ULONG),
("Data2", USHORT),
("Data3", USHORT),
("Data4", BYTE * 8)
]
@classmethod
def from_str(cls, guid_str):
py_uuid = uuid.UUID(guid_str)
uuid_buff = (BYTE * 16)(*py_uuid.bytes)
return ctypes.cast(uuid_buff, ctypes.POINTER(GUID)).contents
class OVERLAPPED(ctypes.Structure):
_fields_ = [
('Internal', ULONG),
('InternalHigh', ULONG),
('Offset', DWORD),
('OffsetHigh', DWORD),
('hEvent', HANDLE)
]
LPOVERLAPPED = ctypes.POINTER(OVERLAPPED)
if sys.platform == 'win32':
LPOVERLAPPED_COMPLETION_ROUTINE = ctypes.WINFUNCTYPE(
None, DWORD, DWORD, LPOVERLAPPED)
else:
LPOVERLAPPED_COMPLETION_ROUTINE = PVOID
class SECURITY_ATTRIBUTES(ctypes.Structure):
_fields_ = [
('nLength', DWORD),
('lpSecurityDescriptor', LPVOID),
('bInheritHandle', BOOL)
]
|