且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有DLL的Python ctypes参数-指向双精度数组的指针

更新时间:2023-02-10 14:18:07

(未测试)应该可以。第四个参数的类型为 POINTER(c_double)。 C的 double returnarray [6] 类型的等效项为 c_double * 6 ,该类型的实例为 returnarray =(c_double * 6)()。另外,如果您声明了参数类型,则无需包装输入参数,例如 int(0);。传递 0 很好:

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)