I created a DLL using C++ and called it from C# long time ago. C# can call C 
functions in DLL using marshall. If I remember correctly, C++ DLL exported some 
C functions, like createObj func create a C++ object and return a pointer to 
it, freeObj takes the pointer and free the object and other functions that 
takes that pointer and do something. In C# code, manage returned pointer 
manually. I also wrote function signatures of exported functions in C# code 
using marshall that is similar to Nim's importc. I didn't got much problems (if 
I remember correctly) and it worked.

You probably be able to do similar thing with Nim. DLL written in Nim export C 
functions using exportc and dynlib pragma. `createNimObj` proc create a ref 
object, increase ref count of it with `GC_ref` and return to C# code. 
`freeNimObj` takes that pointer, decrease ref count with `GC_unref`. And other 
Nim procedures that takes the pointer and do something with the given ref 
object. You probably need to manage the pointer returned from `createNimObj` 
manually unless C# has something like destructor. I didn't used C# for long 
time. 

Reply via email to