Using methods from a project written in C++ in C# (Same Solution)

Asked

Viewed 326 times

0

Hello,

I need to consume methods written in C++ in a project written in C#, within . NET (both) and that are contained in the same Solution (as shown in the image below)

inserir a descrição da imagem aqui

I tried to compile the projects and add the C++ project reference (which was created in DLL->Empty Project mode by visual studio), and when I added (to the C#project) it was not available for me to use the class I am developing in C++

Then I removed the reference and tried to add again (because it had a yellow triangle on top), and now when I try to load the reference, it shows the following error message:

inserir a descrição da imagem aqui

Could someone help me?

I need this because I have to implement a method in Assembly language, and C# doesn’t allow me to program Assembly as C++ does (*it’s a college job, and I didn’t want to write the whole program in C++ but in C#, the point is just Assembly itself)

  • You need to get out of managed code for unmanaged; it’s boring, but that’s what needs to be done

  • Have you tried following these MSDN tips? https://msdn.microsoft.com/en-us/library/ms235282.aspx

1 answer

1


In the properties of your C++ project change the option "Common Language Runtime Support" to "Common Language Runtime Support (/clr)" in "Configuration Properties->General->Project Defaults". Libraries developed without CLR cannot be referenced directly in C#, so you should create your library in C++ using CLR.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.