the question of architecture, where is it correct to declare a class, taking into account that it is used in an application (C #) and two satellite dlls (C ++ clr)? So that it is visible during assembly and linking. Or do it through the interface? But where to announce it?

You can take the simplest class, for example:

ref class XY { property Int32 y; property Int32 x; } 

In C/C++ there is an includ and typedef for this, but how is that?

  • Is the C # label exactly needed here? - default locale
  • one
    Generally speaking, it is about clr Net, the application is written in c #, so it seems to me that it is quite appropriate. - NewView

1 answer 1

Put the class in a separate DLL on C ++ / CLI, and mark it with the public modifier:

 public ref class XY 

After that, just add a link to this DLL in all projects where you need this class, and you can use it. Header files in .NET are not used, since all the necessary information about the types is in the assembly metadata.

It would seem that everything is simple. But there is one problem - assemblies in C ++ / CLI (mixed mode) cannot be AnyCPUs, but in C # they can. Accordingly, if you do, say, a 32-bit build on C ++ / CLI, add a link to it in the AnyCPU project, it will compile, but when it comes to loading this assembly into the 64-bit process, everything will fall. This problem can be solved by creating a separate assembly for each processor architecture and manually loading the necessary AppDomain.AssemblyResolve event at run time in the event handler.

  • Yes, it’s understandable about cross-linking, but this method seriously breeds entities and linking between them. Thanks for the detailed answer, especially about the bit depth. This is probably the shortest and fastest solution to implement. - NewView