问题描述:

The new Visual Studio 2012 has removed the Windows Forms Application (WFA) as a Template. The reason for this has been stated by MS to be that VC++ is not the best way to do a GUI. So for maximum performance and portability, I would like to use C++ for the number-crunching and a C# for the GUI.

Since I am starting from scratch, I see no reason not to use C++/CLI for the C++ development – so all the C++ will be in managed C++. I understand that I can use a C++ DLL, but I would rather not.

I can add a C++/CLI project to a solution that also includes a C# WFA project. I can the run the C++/CLI project to get all the C++ working correctly. But I am puzzled over the best way to give the C# project access to the C++/CLI classes. When I "add reference" to the C# project, it lets me add the C++/CLI project as a reference. But how do I add in a class defined in the C++ to the C# code?

网友答案:

I believe you need to specifically make a managed-class; i.e.

ref class Foo
{
    String ^managedString; 
};

and the public variables must also be managed types;

See

If you add the c++/cli class library as a reference in your c# project, you'll be able to see the class in the namespace and use them like any other class.

相关阅读:
Top