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

    Interface FuncPtrFactory<TRet, TArgs>

    Factory returned by CFUNCTYPE / WINFUNCTYPE.

    interface FuncPtrFactory<
        TRet extends FFIType
        | null = FFIType | null,
        TArgs extends readonly FFIType[] = readonly FFIType[],
    > {
        new FuncPtrFactory(
            address?: number | bigint,
        ): TypedFFIFunction<TArgs, TRet>;
        new FuncPtrFactory(
            fn: (...args: CallbackArgs<TArgs>) => CallbackResult<TRet>,
        ): CallableCallback<TArgs, TRet>;
        restype: FFIType;
        argtypes: FFIType[];
        _isFuncPtr: true;
        bind(
            library: CDLL,
            symbolName: string,
            paramflags: readonly (ParamFlag | readonly [number, string, any])[],
        ): FFIFunction;
        from_param(value: unknown): TypedFFIFunction<TArgs, TRet>;
        in_dll(
            library: Library | CDLL,
            name: string,
        ): TypedFFIFunction<TArgs, TRet>;
        (address?: number | bigint): TypedFFIFunction<TArgs, TRet>;
        (
            fn: (...args: CallbackArgs<TArgs>) => CallbackResult<TRet>,
        ): CallableCallback<TArgs, TRet>;
        (spec: readonly [string, CDLL]): TypedFFIFunction<TArgs, TRet>;
        (
            spec: readonly [string, CDLL],
            paramflags: readonly (ParamFlag | readonly [number, string, any])[],
        ): FFIFunction;
        (
            vtblIndex: number | bigint,
            name: string,
            paramflags?: readonly (ParamFlag | readonly [number, string, any])[],
            iid?: unknown,
        ): FFIFunction;
    }

    Type Parameters

    • Call with a raw address to produce a caller. Without an argument, or with 0/0n, it is a NULL function pointer (address 0n, as Python's P()); calling it throws Error exception: access violation writing 0x0000000000000000 (or rejects for callAsync/callOn). P(null) is a TypeError, as in Python.

      Parameters

      • Optionaladdress: number | bigint

      Returns TypedFFIFunction<TArgs, TRet>

    • Call with a JS function to produce a directly callable, typed C callback, usable as an argument or struct field. Keep it referenced while C may call it; release() frees it. As in Python, a prototype whose restype is a POINTER, a function pointer, a structure or an array cannot make callbacks (TypeError invalid result type for callback function).

      Parameters

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

      Returns CallableCallback<TArgs, TRet>

    • Bind an exported function of a library, optionally with paramflags. Python: prototype((name, dll)) / prototype((name, dll), paramflags).

      Parameters

      • spec: readonly [string, CDLL]

      Returns TypedFFIFunction<TArgs, TRet>

    • Parameters

      • spec: readonly [string, CDLL]
      • paramflags: readonly (ParamFlag | readonly [number, string, any])[]

      Returns FFIFunction

    • Bind a COM vtable slot by index (prototype(vtblIndex, name[, paramflags[, iid]])), Windows only (a TypeError elsewhere, as in Python). Each call takes the interface as its first argument: a ctypes instance holding the interface pointer (a POINTER instance, c_void_p, a Structure, a Buffer), not a number, BigInt or byref().

      Parameters

      • vtblIndex: number | bigint
      • name: string
      • Optionalparamflags: readonly (ParamFlag | readonly [number, string, any])[]
      • Optionaliid: unknown

      Returns FFIFunction

    Index
    restype: FFIType

    Shared metadata; assigning it does not recompile the captured signature.

    argtypes: FFIType[]

    Shared metadata; mutating it does not recompile the captured signature.

    _isFuncPtr: true
    • Bind the factory to a library export with Python-style paramflags. Out params are allocated automatically and returned alone (one value or an array). Returning the original args from errcheck keeps this behavior. callAsync() uses the same output processing and per-call hook snapshot.

      Python ctypes parity: prototype((name, lib), paramflags).

      Parameters

      • library: CDLL
      • symbolName: string
      • paramflags: readonly (ParamFlag | readonly [number, string, any])[]

      Returns FFIFunction

      const proto = WINFUNCTYPE(DWORD, HWND, LPDWORD);
      const fn = proto.bind(user32, "GetWindowThreadProcessId", [
      { dir: "in", name: "hWnd" },
      { dir: "out", name: "pid" },
      ]);
      const pid = fn(hwnd); // positional; thread ID is discarded
      const pid2 = fn({ hWnd: hwnd }); // named
      const pid3 = await fn.callAsync(hwnd); // async, same output processing