I have a problem with dll files, I noticed one oddity if I compile this code
proc helloWorld(): string {.exportc, dynlib.} =
return "Hello World
and compile and then try to run the dll in python or another programming language, then everything is fine, but as soon as you need to give an argument to the function
proc hello(slovo: string): string {.exportc, dynlib.} =
echo slovo
and run like this in python
import ctypes
lb = ctypes.cdll.LoadLibrary("./main.dll")
result = lb.hello("Hello World")
print(result)
then prints
out of memory
how to solve this problem?
p.s. libraries for compatibility with python are not suitable. I want to be able to call a function from a dll, for example on rust or golang
thank you, IT WORKS, but for some reason only one letter is displayed:
import ctypes
lb = ctypes.cdll.LoadLibrary("./main.dll")
result = lb.hello("LOL")
print(result)
proc hello(slovo: cstring): cstring {.exportc, dynlib.} =
echo slovo
python main.py
L
import ctypes
lib = ctypes.cdll.LoadLibrary('./libhello.so')
lib.hello(b"Hello World!")
Also, your Nim function should probably return void instead of cstring.