❔ 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
look up DllImport
and on the c++ side
extern "C" __declspec(dllexport)
to the function signatureno 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
wdym
you cant pass managed objects
what do you mean?
like a c# class instance
what are you actually trying to do?
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
is there any reason you want to use both c# and c++?
no not really
then just pick one language :)
that doesn't really solve my problem though does it?
You don't have a problem thou
You have a weird wish
alright then
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
You can call C methods from C#. The other way around is only possible with managed c++
but how would i cast that to it's original type
what is managed c++
cast what
because you passed a pointer
just index the pointer
and make sure to stay in bounds
or find a way to create an std array from it, if possible
now I'm actually curious, I'll try that myself
yeah i'm confused
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
why would you transfer that using a file?
it doen't matter, main idea was just get that string into C#
by file or by any other way
if your entry point is C# you can just p/invoke and call native code directly and marshal things you need back and forth
Platform Invoke (P/Invoke)
Learn how to call native functions via P/Invoke in .NET.
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.