zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
#
# (C) Copyright 2014 Enthought, Inc., Austin, TX
# All right reserved.
#
# This file is open source software distributed according to the terms in
# LICENSE.txt
#
from __future__ import absolute_import
 
import ctypes
import sys
from ctypes import (
    pythonapi, POINTER, c_void_p, py_object, c_char_p, c_int, c_long, c_int64,
    c_longlong)
from ctypes import cast  # noqa imported here for convenience
from ctypes.wintypes import BYTE
 
from win32ctypes.core.compat import PY3
from ._util import function_factory
 
PPy_UNICODE = c_void_p
LPBYTE = POINTER(BYTE)
is_64bits = sys.maxsize > 2**32
Py_ssize_t = c_int64 if is_64bits else c_int
 
if ctypes.sizeof(c_long) == ctypes.sizeof(c_void_p):
    LONG_PTR = c_long
elif ctypes.sizeof(c_longlong) == ctypes.sizeof(c_void_p):
    LONG_PTR = c_longlong
 
if PY3:
    _PyBytes_FromStringAndSize = function_factory(
        pythonapi.PyBytes_FromStringAndSize,
        [c_char_p, Py_ssize_t],
        return_type=py_object)
else:
    _PyBytes_FromStringAndSize = function_factory(
        pythonapi.PyString_FromStringAndSize,
        [c_char_p, Py_ssize_t],
        return_type=py_object)
 
 
def IS_INTRESOURCE(x):
    return x >> 16 == 0
 
 
byreference = ctypes.byref
 
 
def dereference(x):
    return x.contents
 
 
class Libraries(object):
 
    def __getattr__(self, name):
        library = ctypes.WinDLL(name)
        self.__dict__[name] = library
        return library
 
 
dlls = Libraries()