Category : ctypes

I have no experience in c++ and swig. I would like to use the C++ SDK Rplidar SDK in my python program to improve the performance. After some research, i found swig and ctype are two methods which is able to do that. I am trying swig. However, i cannot write the interface file (.i) ..

Read more

I write C source code like this, aiming to accelerate the Python code with C, so I include some py object and func in C: include header file Python.h and dynamic link file libpython3.8.so. // test.h #include "Python.h" #include <stdio.h> // test.c void main(){ PyObject *bigrams1 = PySet_New(0); ret = PySet_Add(bigrams, PyUnicode_FromWideChar(L"nc", 2)); ret = ..

Read more

c++ extern "C" API void vector_string_test(string* data) { vector<string> vec = {"123abc","456efg"}; std::memcpy(data, vec.data(), vec.size() * sizeof vec[0]);} python dll=dll.LoadLibrary(dll_path) vector_string_test=dll.vector_string_test vector_string_test.argtypes=(POINTER(ctypes.c_wchar_p),) vector_string_test.restype=None data=(c_wchar_p*2)() vector_string_test(data) data_ptr=cast(data,c_char_p) print(data_ptr.value) Then I get: b’123abc’ So How I get all the results in vec with Python´╝č Source: Windows Que..

Read more

I am able to return a string after it is converted to a char* import ctypes from subprocess import Popen, PIPE # Press the green button in the gutter to run the script. libname = "c:tempdebug_api_lib.dll" c_lib = ctypes.windll.LoadLibrary(libname) class Gilad(object): def __init__(self, host, port): c_lib.menu_function_new.argtypes = [ctypes.c_char_p, ctypes.c_int] c_lib.menu_function_new.restype = ctypes.c_void_p c_lib.get_mac_address_new.argtypes = [ctypes.c_void_p] ..

Read more

I am able to return a string after it is converted to a char*. import ctypes from subprocess import Popen, PIPE # Press the green button in the gutter to run the script. libname = "c:tempdebug_api_lib.dll" c_lib = ctypes.windll.LoadLibrary(libname) class Gilad(object): def __init__(self, host, port): c_lib.menu_function_new.argtypes = [ctypes.c_char_p, ctypes.c_int] c_lib.menu_function_new.restype = ctypes.c_void_p c_lib.get_mac_address_new.argtypes = [ctypes.c_void_p] ..

Read more