How to write a function in C ++ and integrate it in python

Question:

I started to study this issue. I am using swig. After assembling the interface file, I do not know how to use the written function in python. If there is a complete example, I will be grateful

Answer:

On the Python side, it would look something like this:

import ctypes

# Подключение системных файлов
syslib = ctypes.cdll.msvcrt  # msvcrt.dll
syslib.printf(b"system DLL!\n")

# Подключение своих файлов
lib = ctypes.cdll.LoadLibrary("./NAME.dll")
lib.PrintData()

# Вариант 2
lib2 = ctypes.CDLL("./NAME.dll")
x = lib2.SumData(5)
print(x)

Dll implements the PrintData and SumData functions, SumData .

Scroll to Top