官网
可以使用C++/CLI在C++和.Net之间联合编程,C++/CLI是一个两栖模块,它具有如下特点
- 既可以访问.Net类库,也可以访问C++原生类库
- 既可以被.Net程序引用,也可以被C++原生程序引用
使用C++/CLI,可以使用C++编写算法,用C#编写界面
C++/CLI(Common Language Infrastructure,通用语言框架)可以简单的认为就是.NET运行的托管C++
C#可以调用Native C++类,也可以调用C++/CLI类,但是区别非常大。
- C#可以调用Native C++类类型,无论使用Pinvoke还是其他方法,Native类类型作为参数都很难处理
- C#可以直接调用ref类,和.net类库内其他类一样
1.ref类的变量(字段)不能使Native C++类类型,可以是指向Native C++类类型对象的指针
2.ref类内部可以直接使用Native C++类类型,只需要导入相关头文件即可
3.ref类的函数(方法)参数可以直接使用Native C++类类型,但是C#无法理解这些参数。也就是说,public函数不要用Native C++类类型作为参数类型
C++/CLI声明的类必须是ref类,即声明方式只能是:
ref class major{};
ref struct major{};
C++/CLI调用C#,在C++/CLI文件内引用C#类库文件和命名空间即可
#using "LMath.dll" using namespace My::LMath;
一 在VS2017/2019 安装 C++/CLI的模块支持
String^ fileName = "textfile.txt"; StreamWriter^ sw = gcnew StreamWriter(fileName);
If you use the sample program, notice thatyou use the gcnew keyword instead of new when creating a .NET object,and that gcnew returns a handle( ^ ) rather than a pointer ( * ):
using namespace System;
using namespace System::IO;
int main()
{
String^ fileName = "textfile.txt";
StreamWriter^ sw = gcnew StreamWriter(fileName);
sw->WriteLine("Hi Major");
sw->Close();
Console::WriteLine("a new file ('{0}') has been written", fileName);
return 0;
}
C++/CLI Tasks
C++/CLI Wrapper
public ref class Point; int x,y; public ref class ContourFinder void load_picture(System::String^ file_name); List参考文档^>^ find_contour(int threshold); property int Rows {int get();} property int cols {int get();}
- https://www.cnblogs.com/TianFang/p/4931879.html



