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

    Class OleDLL

    Load a Windows library whose functions return HRESULT (the default restype). As Python's FUNCFLAG_HRESULT, a negative result raises whatever the restype (HRESULT, c_int, c_long, ...; not null/c_void): an Error with message "[WinError N] <system text>", errno (mapped as Python's OSError), strerror (the system text), filename null, winerror and hresult (signed) and function (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.OleDLL

    import { OleDLL, HRESULT, c_wchar_p, c_void_p } from 'node-ctypes';

    const ole32 = new OleDLL('ole32.dll');
    const CLSIDFromString = ole32.func('CLSIDFromString', HRESULT, [c_wchar_p, c_void_p]);
    // Throws automatically on HRESULT < 0
    CLSIDFromString('{00000000-0000-0000-0000-000000000000}', Buffer.alloc(16));

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

    • 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