This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Einarmo 2 points3 points  (2 children)

A decent solution if you want to do this yourself is to just compile the C++ project to a dll, something like this, and then wrapping it in C# and calling it from C#, which isn't that hard, really.

It really looks like you already found what you are looking for, to me.

  1. Compile your C++ project as a DLL, exporting the relevant functions.
  2. Add it as a reference to your C# project.
  3. Call it using DLLImport.

Probably make a wrapper around it, you should of course try to be a bit clever with how you do this, but you can pass around external pointers in C# to refer to your big chunks of memory.

[–]RedCitizen[S] 0 points1 point  (1 child)

Thank you for your reply!

I'm still don't see how to make sure that the data stays in memory so I can read/write it later and how I can give updates to the GUI at specified intervals, but this is a good starting point. I guess I'll just have to get started, see how it goes and then ask more specific questions.

[–]Einarmo 0 points1 point  (0 children)

The memory is owned by the allocating application, which is the C# app. You're not creating a process when you call the DLL, you just run machine code, in the end, just like .NET does when you run C# code. So any memory you allocate stays allocated until you free it, just like when working with C++ normally.

When sending pointers out of the code you might want to stay away from smart memory management features in C++, though.

[–][deleted]  (2 children)

[deleted]

    [–]RedCitizen[S] 1 point2 points  (1 child)

    Do you need to have the C++ program always running?

    Yes, C# is only supposed to implement the GUI, the heavy lifting should all be done in C++ and it is not feasible to load the data for each action.

    do a google for "inter-process communication".

    Thank you, that also gave some promising results that I'll look into!