B
B
Beginner_programmer2017-03-03 17:05:39
C++ / C#
Beginner_programmer, 2017-03-03 17:05:39

Is it possible to combine programs written in different languages ​​(C++, C#) in one project in VS2012?

For example, the code for calculating a certain task is written in C ++, it is necessary to illustrate the results of the calculation in a "graphical" form (graphs, pictures, etc.) and I would like to have a graphical interface in general using not MFC, but windows form. Is it possible to create a form, buttons, etc. using C #, and the calculation itself in C ++. Let's say that a calculation written in C ++ is performed by pressing a button. How to combine this in one Visual Studio 2012 project?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
15432, 2017-03-03
@15432

Create a Solution with two projects, C# Windows Forms and C++ Win32 DLL.
You write your code in C ++, make a dllexport function that accepts, for example, void *, where the data will be added.
In the C# class, use Dllimport, allocate memory through Marshal.AllocHGlobal, pass it to the C ++ function call, it fills something there, then get it through Marshal.Copy and work with it further

E
Evgeny Shatunov, 2017-03-03
@MarkusD

https://github.com/FrankStain/tex-conv
This is an example of such a project. Multitasking texture converter.
At the top level is a C# application with a UI on WinForms, all work with the user is done here.
The C++/CLI core, which is a class library, is connected to the top level. This core links the top level to the bottom level, which is represented by a potentially uncountable set of plugins.
The class library in C# is used as if it were an ordinary module.
Specifically for your case, I would recommend doing this.

  • The bottom level is a static library project that will contain all your C++ code.
  • The middle level is a C++/CLI class library, into which the lower level is linked, and will link the lower level to the upper one through its classes.
  • A high-level C# application that uses middle-level classes.

J
John_Nash, 2017-03-03
@John_Nash

you can solve the problem in 3 ways
1) c++ cli
2) P/Invoke
3) Com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question