I am passing an array of doubles to a DLL using CTypes. The code is below.
I need to pass a pointer to the array. I have tried to pass it four different ways, as shown in the code. For simplicity, I am passing the same array three times.
TestArrayType = ctypes.c_double * 1000
arrNew = TestArrayType()
hDLL = ctypes.WinDLL(r"C:/NASM_Test_Projects/Test_Project_Full2/Std_Math_Formulas.dll")
CallTest = hDLL.TryThemAll
CallTest.argtypes = [ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double)]
CallTest.restype = ctypes.c_int64
t = type(arrNew)
#Call #1
#ptrA = ctypes.cast(arrNew, ctypes.POINTER(ctypes.c_double))
#retvar = CallTest(ptrA, ptrA, ptrA)
#Call #2
#retvar = CallTest(ctypes.pointer(arrNew), ctypes.pointer(arrNew), ctypes.pointer(arrNew))
#Call #3
#retvar = CallTest(ctypes.POINTER(arrNew), ctypes.POINTER(arrNew), ctypes.POINTER(arrNew))
#Call #4
retvar = CallTest(arrNew, arrNew, arrNew)
The four different calls above give the following error messages:
Call #1: Message=exception: access violation reading 0x000000000000000D
Call #2: ctypes.ArgumentError: argument 1: : expected LP_c_double instance instead of LP_c_double_Array_1000
Call #3: must be a ctypes type
Call #4: Message=exception: access violation reading 0xFFFFFFFFFFFFFFFF
So I'm not doing it right yet. I've done a lot of research, but I still haven't found the right way to pass pointers to the array.
The value of t in the expression t = type(arrNew) is:
t = class Trans_01_Samples_04.c_double_Array_1000
Thanks in advance for any help.