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

    Interface PointerTypeDef<T>

    A pointer type created by POINTER.

    const IntPtr = POINTER(c_int32);

    // From existing buffer
    const p = IntPtr.fromBuffer(buf);
    console.log(p.contents.value); // 42
    console.log(p[0]); // 42

    // From raw address (e.g., from a struct's c_void_p field)
    const pValues = POINTER(MyStruct).fromAddress(someStruct.pData);
    console.log(pValues[0].field1);
    interface PointerTypeDef<T = any> {
        new PointerTypeDef(value?: PointerConstructTarget): PointerInstance<T>;
        name: string;
        prototype: PointerInstance<T>;
        from_param(value: unknown): unknown;
        _pointerTo: T;
        _type_: T;
        set_type(
            type:
                | SimpleCDataConstructor<string>
                | StructDef<Record<string, any>>
                | UnionDef<Record<string, any>>
                | StructureClass
                | PointerTypeDef<any>
                | ArrayTypeDef<any>,
        ): void;
        __pointer_type__?: PointerTypeDef<PointerTypeDef<T>>;
        _baseSize: number;
        size: number;
        create(value?: number | bigint | PointerTargetInstance): PointerInstance<T>;
        fromBuffer(targetBuf: Buffer): PointerInstance<T>;
        fromAddress(address: number | bigint): PointerInstance<T>;
        from_buffer(
            source: ArrayBufferView<ArrayBufferLike> | { _buffer: Buffer },
            offset?: number | boolean,
        ): PointerInstance<T>;
        from_buffer_copy(
            source:
                | ReadonlyMemoryView
                | ArrayBufferView<ArrayBufferLike>
                | { _buffer: Buffer },
            offset?: number | boolean,
        ): PointerInstance<T>;
        from_address(address: number | bigint): PointerInstance<T>;
        in_dll(library: Library | CDLL, name: string): PointerInstance<T>;
        deref(ptrBuf: Buffer): bigint;
        set(ptrBuf: Buffer, value: bigint | Buffer<ArrayBufferLike>): void;
        toString(): string;
    }

    Type Parameters

    • T = any
    Index
    • Python LP() / LP(obj): a NULL pointer, or a pointer to a ctypes instance (a pointer instance is pointed at through its slot). p instanceof LP holds for the instances of this type. The type can also be called without new (LP(obj)); only the construct signature is declared, so that [POINTER(T)] keeps the inference of callback argument types.

      Parameters

      • Optionalvalue: PointerConstructTarget

      Returns PointerInstance<T>

    name: string

    Python type name (LP_c_int32).

    prototype: PointerInstance<T>
    _pointerTo: T

    The resolved base type, including for lazy pointer declarations; null for an incomplete POINTER('Name') type.

    _type_: T

    Python ctypes alias for the resolved base type (undefined for an incomplete type).

    __pointer_type__?: PointerTypeDef<PointerTypeDef<T>>

    Python 3.14 T.__pointer_type__: the type POINTER(T) returns for this pointer type (undefined before the first one).

    _baseSize: number

    Size of the pointed-to type.

    size: number

    Pointer size (always 8 on 64-bit).

    • Python Pointer.from_param: null, a compatible pointer or array, byref() of a compatible instance, or an instance of the pointee type (passed by reference); otherwise a TypeError.

      Parameters

      • value: unknown

      Returns unknown

    • Create a pointer: NULL without an argument (or with null), to a ctypes instance or Buffer, or to a raw address (Number/BigInt, a Node extension kept from 2.x; Python's constructor takes no address).

      Parameters

      • Optionalvalue: number | bigint | PointerTargetInstance

      Returns PointerInstance<T>

      const p = POINTER(c_int32).create();
      console.log(p.isNull); // true
      const q = POINTER(c_int32).create(0x1000n); // q.address === 0x1000n
    • Create a pointer from an existing buffer (points to that buffer's memory).

      Parameters

      • targetBuf: Buffer

        Buffer to point to

      Returns PointerInstance<T>

      const buf = Buffer.alloc(4);
      buf.writeInt32LE(42, 0);
      const p = POINTER(c_int32).fromBuffer(buf);
      console.log(p.contents.value); // 42
    • Create a pointer from a raw memory address.

      Use this to create typed access to native memory, especially useful with c_void_p struct fields that point to arrays of structs.

      Parameters

      • address: number | bigint

        Memory address as BigInt or number

      Returns PointerInstance<T>

      // Access array of structs from a c_void_p field
      const pValues = POINTER(ADSVALUE).fromAddress(col.pADsValues);
      for (let i = 0; i < col.dwNumValues; i++) {
      console.log(pValues[i].dwType);
      }
    • Python POINTER(T).from_buffer(source, offset): a pointer whose own slot (the void * value) is the memory of source at offset, so writing .contents updates source (unlike fromBuffer, which points to the Buffer). A short source throws RangeError Buffer size too small (N instead of at least M bytes).

      Parameters

      • source: ArrayBufferView<ArrayBufferLike> | { _buffer: Buffer }
      • Optionaloffset: number | boolean

      Returns PointerInstance<T>

    • Python POINTER(T).from_buffer_copy(source, offset): a pointer whose slot is a copy of the pointer value in source.

      Parameters

      • source: ReadonlyMemoryView | ArrayBufferView<ArrayBufferLike> | { _buffer: Buffer }
      • Optionaloffset: number | boolean

      Returns PointerInstance<T>

    • Parameters

      • ptrBuf: Buffer

      Returns bigint

      Use pointer instance .contents instead. Legacy API: Dereferences a pointer buffer.

    • Parameters

      • ptrBuf: Buffer
      • value: bigint | Buffer<ArrayBufferLike>

      Returns void

      Use pointer instance .set() instead. Legacy API: Sets pointer buffer value.