Skip to content

Kernel32 (Windows __stdcall)¤

Wrapper around the 32-bit Windows __stdcall library, kernel32.dll.

Example of a server that loads a 32-bit Windows library, kernel32.dll, in a 32-bit Python interpreter to host the library. The corresponding Kernel64 class is created in a 64-bit Python interpreter and the Kernel64 class sends requests to the Kernel32 class which calls the 32-bit library to execute the request and then returns the response from the library.

Note

This example is only valid on Windows.

Kernel32 ¤

Kernel32(host, port)

Bases: Server32

Wrapper around the 32-bit Windows __stdcall library.

Parameters:

Name Type Description Default
host str

The IP address (or hostname) to use for the server.

required
port int

The port to open for the server.

required
Source code in src/msl/examples/loadlib/kernel32.py
27
28
29
30
31
32
33
34
35
36
def __init__(self, host: str, port: int) -> None:
    """Wrapper around the 32-bit Windows `__stdcall` library, [kernel32.dll]{:target="_blank"}.

    [kernel32.dll]: https://www.geoffchappell.com/studies/windows/win32/kernel32/api/

    Args:
        host: The IP address (or hostname) to use for the server.
        port: The port to open for the server.
    """
    super().__init__("C:/Windows/SysWOW64/kernel32.dll", "windll", host, port)

get_local_time ¤

get_local_time()

Calls the kernel32.GetLocalTime function to get the current date and time.

See the corresponding Kernel64.get_local_time method.

Returns:

Type Description
datetime

The current date and time.

Source code in src/msl/examples/loadlib/kernel32.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def get_local_time(self) -> datetime:
    """Calls the [kernel32.GetLocalTime]{:target="_blank"} function to get the current date and time.

    See the corresponding [Kernel64.get_local_time][msl.examples.loadlib.kernel64.Kernel64.get_local_time] method.

    [kernel32.GetLocalTime]: https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlocaltime

    Returns:
        The current date and time.
    """
    st = SystemTime()
    self.lib.GetLocalTime(ctypes.byref(st))
    return datetime(  # noqa: DTZ001
        st.wYear,
        month=st.wMonth,
        day=st.wDay,
        hour=st.wHour,
        minute=st.wMinute,
        second=st.wSecond,
        microsecond=st.wMilliseconds * 1000,
    )

SystemTime ¤