我正在尝试使用 cTypes 将字符串(作为指针)从 python 传递到 C 函数。
\n\nc 函数需要获取指向字符串(字符数组)的指针,但我还没有成功地让它与多个字符一起工作,但我唯一的成功(有点成功,看看输出)是使用 1 个字符和希望得到一些帮助!
\n\n我需要将字符串的指针发送到 char - (unsigned char * 输入)
\n\n我的Python代码:
\n\ndef printmeP(CHAR):\n print("In Print function")\n print(CHAR)\n c_sends = pointer(c_char_p(CHAR.encode(\'utf-8\')))\n print("c_sends: ")\n print(c_sends[0])\n python_p_printme(c_sends)\n print("DONE function - Python")\n print(c_sends[0])\n return\n\n\nfrom ctypes import c_double, c_int,c_char, c_wchar,c_char_p, c_wchar_p, pointer, POINTER,create_string_buffer, byref, CDLL\nimport sys\n\nlib_path = \'/root/mbedtls/programs/test/mylib_linux.so\' .format(sys.platform)\n\n\nCHAR = "d"\n\ntry:\n mylib_lib = CDLL(lib_path)\nexcept:\n print(\'STARTING...\' )\npython_p_printme = mylib_lib.printme\npython_p_printme.restype = None\nprintmeP(CHAR)\n\n\nRun Code Online (Sandbox Code Playgroud)\n\n我的C代码:
\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nvoid printme(char * param) {\n printf("\\nStart c …Run Code Online (Sandbox Code Playgroud)