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

    Class CDLL

    Hierarchy (View Summary)

    Indexable

    • [funcName: string]: any

      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.

    Index
    • Parameters

      • path: string

        Path to the shared library, or null to load the current process (Linux and macOS; on Windows null throws TypeError LoadLibrary() argument 1 must be str, not None unless options.handle is given, as in CPython). A name with a NUL character is a RangeError (embedded null character on Windows, embedded null byte elsewhere; Python ValueError). On Windows, "" throws Error [WinError 87] <system text> (winerror 87, as CPython's OSError), and a library that cannot be found throws Error Could not find module '<name>' (or one of its dependencies). Try using the full path with constructor syntax. with errno 2 (CPython: FileNotFoundError).

      • Optionaloptions: number | LibraryOptions

        dlopen mode (as Python's CDLL(name, mode)) or library settings (mode, cache size, use_last_error, use_errno)

      Returns CDLL

    path: string

    Library file path.

    _name: string

    Python ctypes lib._name: the name passed to the constructor (null for the current process).

    _handle: bigint

    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).

    loaded: boolean

    Whether the logical handle is open, independently of physical module residency.

    • Get the address of a symbol.

      Parameters

      • name: string

        Symbol name

      Returns bigint

      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.

      Returns void

    • Close the library at the end of a using block.

      Returns void

    • Create a native callback bound to this library's context. Call release() when it is no longer needed.

      Type Parameters

      • TRet extends CallbackRestype
      • const TArgs extends readonly FFIType[] = readonly []

      Parameters

      • fn: (...args: CallbackArgs<TArgs>) => CallbackResult<TRet>
      • returnType: TRet
      • OptionalargTypes: TArgs

      Returns Callback

    • 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().

      Returns number

    • 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().

      Returns number

    • 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.

      Parameters

      • name: string | number | bigint | boolean

      Returns FunctionWrapper