According to this question: Read char16_t* String with cppyy from c++ I have a new problem with the char16_t* in a user defined struct.
Given a C++ function:
MLPI_API MLPIRESULT mlpiMotionGetConfiguredAxes(const MLPIHANDLE connection, MlpiAxisInformation* configAxes, const ULONG numElements, ULONG *numElementsRet);
typedef unsigned int ULONG;
typedef char16_t WCHAR16;
typedef struct MlpiAxisInformation
{
MlpiAxisRef axis; //!< Logical axis address.
ULONG deviceAddress; //!< (SERCOS) device address.
MlpiAxisType axisType; //!< Type of axis (virtual, real, etc...).
WCHAR16 name[MLPI_MOTION_MAX_AXIS_NAME_LEN]; //!< The axis name.
}MlpiAxisInformation;
For ctypes I defined the structures as classes and built an array from it. But then the string does not work. Cppyy is able to handle the sting, but I have no clue how to hand over the array and wrap the string then..
(Working) Vanilla ctypes-code:
class MlpiAxisRef(ctypes.Structure):
_fields_ = [
("controlNo",ctypes.c_int),
("axisNo",ctypes.c_int)]
class MlpiAxisInformation(ctypes.Structure):
_fields_ = [
("axis", MlpiAxisRef),
("deviceAddress",ctypes.c_ulong),
("axisType", ctypes.c_int),
("name", ctypes.c_wchar*100)
]
def MLPIGetConfiguredAxes(self) -> List[MlpiAxisInformation]:
length = ctypes.c_ulong(99)
length_ret = ctypes.c_ulong(0)
self._mlpi.mlpiMotionGetConfiguredAxes.argtypes = (ctypes.c_ulonglong, ctypes.POINTER(MlpiAxisInformation), ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong))
self._mlpi.mlpiMotionGetConfiguredAxes.restype = ctypes.c_long
val = (MlpiAxisInformation*100)()
ret = self._mlpi.mlpiMotionGetConfiguredAxes(self.con, val, length, length_ret)
How to get back the MlpiAxisInformation-Array with working strings?
cppyy = "==1.7.0" due to problems in dockerize later versions..