Here is a ctypes wrapper to call a DLL. It reads a simple text file as a byte array (utf-8 encoding), creates a string buffer of the same length, and passes both to the DLL. With the code below, I get the error: expected LP_c_char_p instance instead of c_char_Array_8049.
I have also tried passing the two arrays as ctypes.c_byte but that didn't work either.
file_name = r"C:\Projects\--Data_Files\Strings\Sample_Text.txt"
f = io.open(file_name, mode="r", encoding="utf-8")
CA_my_str = f.read()
CA_no_punct = ctypes.create_string_buffer(len(CA_my_str))
Input_Length_Array = []
Input_Length_Array.append(len(CA_no_punct))
Input_Length_Array.append(len(CA_my_str))
length_array_out = (ctypes.c_double * len(Input_Length_Array))(*Input_Length_Array)
hDLL = ctypes.WinDLL("C:/NASM_Test_Projects/String_Processing/String_Processing.dll")
CallName = hDLL.Main_Entry_fn
CallName.argtypes = [ctypes.POINTER(ctypes.c_char_p),ctypes.POINTER(ctypes.c_char_p), ctypes.POINTER(ctypes.c_double)]
CallName.restype = ctypes.POINTER(ctypes.c_double)
ret_ptr = CallName(CA_no_punct, CA_my_str, length_array_out)
So the question is: what's the correct ctypes argtype for the two arrays CA_my_str and CA_no_punct?
EDIT: per request below, here is the entry point in NASM:
Main_Entry_fn:
push rdi
push rbp
mov [no_punct_ptr],rcx
mov [my_str_ptr],rdx
mov [data_master_ptr],r8
; Now assign lengths
lea rdi,[data_master_ptr]
mov rbp,[rdi]
xor rcx,rcx
movsd xmm0,qword[rbp+rcx]
cvttsd2si rax,xmm0
mov [no_punct_length],rax
add rcx,8
movsd xmm0,qword[rbp+rcx]
cvttsd2si rax,xmm0
mov [my_str_length],rax
add rcx,8
call String_Processing_fn
exit_label_for_Main_Entry_fn:
pop rbp
pop rdi
ret
Main_Entry_Fn).ctypes.POINTER(ctypes.c_char_p)is a double pointer (equivalent ofchar **). Is that what you're after?double*for the two integer (and same) string lengths? You could get by withc_size_t.