Python-like function access. Accessing any property returns a FunctionWrapper
that supports argtypes/restype assignment. name in lib is true for
the exports that resolve; reading a missing export throws an error named
AttributeError.
Optionaloptions: number | LibraryOptionsReadonlypathLibrary file path.
Readonly_Python ctypes lib._name: the name passed to the constructor (null for the current process).
Readonly_Native OS module handle address (lib._handle); it stays the same after
close(). With an explicit LibraryOptions.handle it is the value
given, as a BigInt with its sign (-1n for handle: -1, as CPython).
ReadonlyloadedWhether the logical handle is open, independently of physical module residency.
Typed overload: narrows args/return when argTypes is a literal tuple.
Optionaloptions: FunctionOptionsTyped overload: narrows args/return when argTypes is a literal tuple.
Typed overload: narrows args/return when argTypes is a literal tuple.
OptionalargTypes: FFIType[]Optionaloptions: FunctionOptionsGet the address of a symbol.
Symbol name
Address as BigInt
Close the library and clear the function cache. Functions obtained from
it throw when called afterwards. Throws while a call to one of its
functions is in progress (from a callback, or a pending callAsync()).
Existing in_dll() views defer native handle release until their dependent
memory is collected, but new calls and symbol lookups are rejected.
Physical unloading depends on the OS loader; musl keeps modules resident.
Close the library at the end of a using block.
The thread's ctypes-private copy of GetLastError() (Windows), the same
value as the global get_last_error (a signed C int): functions
created with use_last_error swap it with the system value around each call.
A Node extension (Python has only the global): it throws Error
Library was not opened with use_last_error: true unless the library was
opened with LibraryOptions.use_last_error.
Python ctypes parity: ctypes.get_last_error().
The thread's ctypes-private copy of errno, the same value as the global
get_errno: functions created with use_errno swap it with the
system value around each call. A Node extension: it throws Error
Library was not opened with use_errno: true unless the library was
opened with LibraryOptions.use_errno.
Python ctypes parity: ctypes.get_errno().
Python lib[name]: a new function for the C export name, also when a
library member has the same name (lib.__getitem__("close") is the C
close). Throws an error named AttributeError when the export is missing.
An integer (Number, BigInt or boolean) is an export ordinal on Windows
(Python lib[1]; JS lib[1] is the name "1", so use __getitem__):
it is masked to 16 bits, a missing one throws AttributeError
function ordinal N not found, and the function has no __name__.
Other values throw TypeError
function name must be string, bytes object or integer.
Load a Windows library whose functions return
HRESULT(the default restype). As Python'sFUNCFLAG_HRESULT, a negative result raises whatever the restype (HRESULT,c_int,c_long, ...; notnull/c_void): an Error withmessage"[WinError N] <system text>",errno(mapped as Python's OSError),strerror(the system text),filenamenull,winerrorandhresult(signed) andfunction(a description of the binding, e.g."OleDLL 'CLSIDFromString'"). A result that does not convert to a C long is a TypeError (a float restype) or a RangeError (out of range). A restype class with its own_check_retval_replaces the HRESULT check, as in CPython.Python equivalent:
ctypes.OleDLLExample