码迷,mamicode.com
首页 > 编程语言 > 详细

C++访问托管类(C#类库)

时间:2016-09-10 13:10:32      阅读:570      评论:0      收藏:0      [点我收藏+]

标签:

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);

 

C++访问托管类(C#类库)

标签:

原文地址:http://www.cnblogs.com/profession/p/5859044.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!