node-ctypes - v2.10.0
    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;
        (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;
    }

    Type Parameters

    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