1、新建C# 类库项目Airth,新建类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Arith
{
    public class MathCalc
    {
        public int Add(int a, int b)
        {
            return a + b;
        }

        public int Dec(int a, int b)
        {
            return a - b;
        }
    }
}

2、新建C++项目,支持CLR

  头文件中加入

#using <mscorlib.dll>
#using "../debug/Arith.dll"
using namespace System;
using namespace Arith;

3、创建访问对象

gcroot<MathCalc ^>  mathCls;    //头文件中
mathCls = gcnew MathCalc();      //cpp中

4、使用方法

 

 int result = mathCls->Add(4,1);
 int result = mathCls->Dec(4,1);

 

相关文章:

  • 2022-12-23
  • 2022-03-06
  • 2021-12-14
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2021-06-19
猜你喜欢
  • 2021-09-17
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-01-06
相关资源
相似解决方案