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

    Interface PointerInstance<T>

    A pointer instance created by PointerTypeDef.create, PointerTypeDef.fromBuffer, or PointerTypeDef.fromAddress.

    Supports Python ctypes-compatible .contents property and C-like [index] pointer arithmetic.

    const IntPtr = POINTER(c_int32);
    const p = IntPtr.fromBuffer(buf);
    console.log(p.contents.value); // dereferenced value (like *p in C)
    console.log(p[0]); // same as p.contents
    console.log(p[5]); // pointer arithmetic (like p[5] in C)
    // When a struct has a c_void_p field pointing to an array of structs:
    const pValues = POINTER(ADSVALUE).fromAddress(col.pADsValues);
    for (let i = 0; i < col.dwNumValues; i++) {
    console.log(pValues[i].dwType); // struct view at pValues + i * sizeof(ADSVALUE)
    }
    interface PointerInstance<T = any> {
        _pointerType: PointerTypeDef<T>;
        _baseType: AnyType | StructDef<Record<string, any>>;
        _type_: T;
        _baseSize: number;
        address: bigint;
        get contents(): PointerContents<T>;
        set contents(value: ContentsArg<T>): void;
        _buffer: Buffer<ArrayBufferLike>;
        deref(): PointerContents<T>;
        set(
            value:
                | number
                | bigint
                | Buffer<ArrayBufferLike>
                | PointerInstance<any>
                | { _buffer: Buffer },
        ): void;
        isNull: boolean;
        toBuffer(): Buffer;
        toString(): string;
        add(n: number): PointerInstance<T>;
        slice(
            this:
                | PointerInstance<SimpleCDataConstructor<"char">>
                | PointerInstance<SimpleCDataConstructor<"wchar">>,
            start: number,
            end: number,
        ): string;
        slice(start: number, end: number): PointerValue<T>[];
        [index: number]: PointerValue<T>;
    }

    Type Parameters

    • T = any

    Indexable

    • [index: number]: PointerValue<T>

      Pointer arithmetic — access elements at offset from the pointer.

      p[i] reads sizeof(baseType) bytes at address + i * sizeof(baseType), exactly like C pointer indexing.

      const arr = POINTER(c_int32).fromAddress(arrayAddr);
      arr[0] // first element
      arr[5] // sixth element
      arr[2] = 99; // write to third element
    Index
    _pointerType: PointerTypeDef<T>

    The pointer type definition this instance was created from.

    _baseType: AnyType | StructDef<Record<string, any>>

    The base type this pointer points to.

    _type_: T

    Python pointer(x)._type_: the pointee type of the pointer's class (undefined while incomplete).

    _baseSize: number

    Size of the pointed-to type in bytes.

    address: bigint

    Raw memory address as BigInt.

    _buffer: Buffer<ArrayBufferLike>

    The underlying buffer (if created from a buffer), or null.

    isNull: boolean

    Check if this is a NULL pointer.

    • get contents(): PointerContents<T>

      The pointed object, as Python's p.contents: a live instance on the pointed memory (p.contents.value for simple types, p.contents.x for structures). Assigning any ctypes instance re-points the pointer to it (a pointer through its own slot), whatever its type, as Python; assigning a plain value writes it.

      Returns PointerContents<T>

      const p = POINTER(c_int32).fromBuffer(buf);
      console.log(p.contents.value); // read value
      p.contents = 42; // write value
      p.contents = new c_int32(7); // re-point
    • set contents(value: ContentsArg<T>): void

      Parameters

      • value: ContentsArg<T>

      Returns void

    • Alias for the contents getter.

      Returns PointerContents<T>

    • Set pointer to a new target (buffer, ctypes instance, pointer, address, or null).

      Parameters

      • value:
            | number
            | bigint
            | Buffer<ArrayBufferLike>
            | PointerInstance<any>
            | { _buffer: Buffer }

      Returns void

    • Get pointer as an 8-byte buffer containing the address.

      Returns Buffer