C
C#2y ago
annoyingb

❔ binding c# and c++

so I am trying to bind C# and C++ but I don't know how to get any variable from C# to C++.
26 Replies
sibber
sibber2y ago
look up DllImport and on the c++ side extern "C" __declspec(dllexport) to the function signature
annoyingb
annoyingbOP2y ago
no what I mean is like you can put any variable inside and it will be handled by c like I can put a string or int or my own class anything
sibber
sibber2y ago
wdym you cant pass managed objects
annoyingb
annoyingbOP2y ago
what do you mean?
sibber
sibber2y ago
like a c# class instance what are you actually trying to do?
annoyingb
annoyingbOP2y ago
i want to have a list of objects that want to be showed and be editable on your screen and i want to try that through c# and c
sibber
sibber2y ago
is there any reason you want to use both c# and c++?
annoyingb
annoyingbOP2y ago
no not really
sibber
sibber2y ago
then just pick one language :)
annoyingb
annoyingbOP2y ago
that doesn't really solve my problem though does it?
Pobiega
Pobiega2y ago
You don't have a problem thou You have a weird wish
annoyingb
annoyingbOP2y ago
alright then
sibber
sibber2y ago
if you really want to do that, probably the only way you can have a shared list is to manually allocate an array of structs and pass the pointer and length to the c++ side
Pobiega
Pobiega2y ago
You can call C methods from C#. The other way around is only possible with managed c++
annoyingb
annoyingbOP2y ago
but how would i cast that to it's original type what is managed c++
sibber
sibber2y ago
cast what
annoyingb
annoyingbOP2y ago
because you passed a pointer
sibber
sibber2y ago
just index the pointer and make sure to stay in bounds or find a way to create an std array from it, if possible
Scottek utek
Scottek utek2y ago
now I'm actually curious, I'll try that myself
annoyingb
annoyingbOP2y ago
yeah i'm confused
Scottek utek
Scottek utek2y ago
I was wondering if it's not possible to store the address to the allocated memory in a txt file and in C# read the file, go to that memory and read it. but you have to take care of reading the file only after C++ script is done but it's kinda pofider way to do it
Jimmacle
Jimmacle2y ago
why would you transfer that using a file?
Scottek utek
Scottek utek2y ago
it doen't matter, main idea was just get that string into C# by file or by any other way
Jimmacle
Jimmacle2y ago
if your entry point is C# you can just p/invoke and call native code directly and marshal things you need back and forth
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server