Skip to content Skip to sidebar Skip to footer

Python Ctypes Arguments With DLL - Pointer To Array Of Doubles

I am a newbie coder working with ctypes in Python, and attempting to use functions from a DLL written in C. I have found a lot of similar questions to mine on SO but nothing that a

Solution 1:

This (untested) should work. The 4th parameter is type POINTER(c_double). The equivalent of C's double returnarray[6] type is c_double * 6 and an instance of that type is returnarray= (c_double * 6)(). Also, if you've declared the argument types you don't need to wrap the input parameters such as int(0); passing 0 is fine:

dll = windll.LoadLibrary(# file path)

# retype the args for swe_calc_ut
py_swe_calc_ut = dll.swe_calc_ut
py_swe_calc_ut.argtypes = [c_double, c_int, c_int, POINTER(c_double), c_char_p]
py_swe_calc_ut.restype = None

tdj = 1.5 # some value
returnarray = (c_double * 6)()
errorstring = create_string_buffer(126)

py_swe_calc_ut(tjd, 0, 64*1024, returnarray, errorstring)

Post a Comment for "Python Ctypes Arguments With DLL - Pointer To Array Of Doubles"