node-ctypes - v2.17.1
    Preparing search index...

    Windows API

    wintypes is Python's ctypes.wintypes: the same types (BOOL, BYTE, WORD, DWORD, HANDLE, HWND, LPARAM, WPARAM, LPCWSTR, …), structures (RECT, POINT, SIZE, MSG, FILETIME, WIN32_FIND_DATAW, …) and pointer types (LPDWORD = POINTER(DWORD), LPRECT, PHANDLE, …), plus common extras (LRESULT, UINT_PTR, LSTATUS, …).

    import { WinDLL, Structure, POINTER, byref, wintypes } from "node-ctypes";
    const { WORD, HWND, BOOL, RECT, LPRECT } = wintypes;

    const kernel32 = new WinDLL("kernel32.dll");

    class SYSTEMTIME extends Structure {
    static _fields_ = [
    ["wYear", WORD],
    ["wMonth", WORD],
    ["wDayOfWeek", WORD],
    ["wDay", WORD],
    ["wHour", WORD],
    ["wMinute", WORD],
    ["wSecond", WORD],
    ["wMilliseconds", WORD],
    ];
    }

    kernel32.GetLocalTime.argtypes = [POINTER(SYSTEMTIME)];
    kernel32.GetLocalTime.restype = null;
    const st = new SYSTEMTIME();
    kernel32.GetLocalTime(byref(st));

    const user32 = new WinDLL("user32.dll");
    user32.GetClientRect.argtypes = [HWND, LPRECT];
    user32.GetClientRect.restype = BOOL;
    const rect = new RECT();
    user32.GetClientRect(hwnd, byref(rect));
    rect.right - rect.left; // LONG (c_long) values are BigInt

    prototype(vtblIndex, name[, paramflags[, iid]]) creates a COM method caller, as in CPython, on Windows only. Its first argument is the this object: a ctypes instance whose first pointer is the interface pointer, such as pointer(obj), a c_void_p holding the interface address, a Structure whose first field is the vtable pointer, or a create_string_buffer(). Numbers, BigInts, null and byref() raise TypeError (Expected a COM this pointer as first argument); a NULL interface raises RangeError (NULL COM pointer access, CPython ValueError).

    const IUnknown_Release = WINFUNCTYPE(ULONG)(2, "Release");
    IUnknown_Release(pUnknown); // pUnknown: POINTER(IUnknown) or c_void_p

    errcheck receives the method and the arguments without this. With callAsync() / callOn(), this stays alive until the promise settles.