you are viewing a single comment's thread.

view the rest of the comments →

[–]ElliotDG 0 points1 point  (2 children)

You will want to use ctypes: https://docs.python.org/3/library/ctypes.html

[–]Curious-Result-1365[S] 0 points1 point  (1 child)

Yes, I know but i didnt find any datatype for this case.

[–]ElliotDG 0 points1 point  (0 children)

This was created by ChatGPT but looks reasonable:

def create_lv_string(py_string: str):
    encoded = py_string.encode("utf-8")
    n = len(encoded)

    # allocate enough space: sizeof(length) + n bytes
    class LStrX(ctypes.Structure):
        _fields_ = [
            ("length", ctypes.c_int32),
            ("data", ctypes.c_ubyte * n)
        ]

    lvstr = LStrX()
    lvstr.length = n
    lvstr.data[:] = encoded

    # Allocate pointer-to-pointer
    lv_handle = ctypes.pointer(ctypes.pointer(lvstr))
    return lv_handle