Question

I have two managed c++ classes . Which is used to communicate with i2C device. I need to use them in c#. i have 2 ".h" files which have source and declaration. Do I need to convert it to c# or if I am creating a DLL from that how can I do that?

code is sth like :

public ref class Class1 
{
   AnotherClass object = new Anotherclass();
   Method1();
   method2()
}

public ref class AnotherClass
{
}
Était-ce utile?

La solution

Add the C++/CLI and the C# project into the same solution. Then add a reference from the C# project to the C++/CLI project

Autres conseils

The point of using a ref class is to let the C++/CLI compiler generate metadata for the class into the assembly. No need for a .h file, any .NET compiler can read that metadata and use that class.

Just add the reference in your C# project. Best done by having both the C++/CLI project and the C# project in the same solution so you can use a project reference. Right-click the C# project, Add Reference, Project tab.

Simply write a wrapper of these functions in C++ (CLI), and it can then be visible and consumed by .NET by creating the relevant references in the project.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top