N
N
nameOfUser 1232017-06-20 13:57:33
PHP
nameOfUser 123, 2017-06-20 13:57:33

How to combine 2 languages ​​C++ and C#?

Hello!
I would like to write the interface in C#, but the calculations of the program in C++.
I read about different methods of how to do this type, but in the end I only got more confused.
As I understand it, there are such ways:
1. Create a separate Win32 DLL project. for C++ and another project for C#, and using the
Dllimport/Dllexport functions to pass values.
2. Write in C++/CLI. Only here I do not understand how to combine them.
Well, I wrote the code in C ++ / CLI, but how can I insert it into a project written in C #?
3. You can also use COM, but I don't understand what this means.
Is it meant to use to create a C++ MFC project and manage without C#?
Here is my confusion.
What do you think is the most convenient and correct way to combine two languages?
And how it is done (please describe it in detail)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Bay, 2018-11-13
@ortsuev33

You yourself have identified the disadvantage.
What can it lead to? Yes, a lot. For example, you have an application that works with finances. You uploaded 15 items out of 70 and failed. Where to dig? what to do?
The solution is to form one request and immediately send it.
Read about transactions, wrap your function in a transaction.

E
Evgeny Shatunov, 2017-06-20
@capitanx9

2. Write in C++/CLI. Only here I do not understand how to combine them.
Well, I wrote the code in C ++ / CLI, but how can I insert it into a project written in C #?

This option is well chewed in these two questions.
Is it possible to combine programs written in different languages ​​(C++, C#) in one project in VS2012?
How to dynamically link libraries?
This option actually turned out to be the most successful, because dividing the project into three parts (C ++; CLI; C #) also strictly divides the areas of responsibility. On the C# side, only the interface remains, on the CLI side, only the low-level communication, on the C++ side, only the low-level.
The integrity of the code is preserved, the low-level library can be connected with equal ease both to the CLI library and to another low-level project.

P
Peter, 2017-06-20
@petermzg

If you want to use the library in the future in other projects that are not tied to .NET, then option 1.
MFC is for the GUI, it has little to do with COM.
COM is used until the application is highly modular. To do this, the COM library is registered in the windows registry, do you need it?
Also in .NET there is a problem of working with COM when inheriting interfaces.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question