zoukankan      html  css  js  c++  java
  • C++、C#互调用之C++ 调用C# dll

    1、c# 创建dll

    建立C#编写的DLL程序AddDll,项目类型为:类库

    程序代码:

    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace AddDll
    {
        public class Add
        {
            public int iadd(int a, int b)
            {
                int c = a + b;
                return c;
            }
        }
    }

    2、C++编写调用程序

    建立C++的Win32控制台应用程序UseDll,项目类型为:Win32控制台应用程序

    配置:右键点击解决方案资源管理器中的UseDll,选择“属性”,将公共语言运行库支持设置为“公共语言运行库支持(/clr)”

    程序代码:

    #include "stdio.h"
    
    #using "..\debug\AddDll.dll"
    using namespace AddDll;
    
    int main()
    {
            int result;
            Add ^add = gcnew Add();   //生成托管类型
    

    //gcnew creates an instance of a managed type (reference or value type) on the garbage

    //collected heap. The result of the evaluation of a gcnew expression is a handle (^) to

    //the type being created.

            result = add->iadd(10,90);
            printf("%d",result);
            scanf("%s");
            return 0;
    }


     

  • 相关阅读:
    作业
    第四次作业
    第三次作业
    作业
    第4次作业
    第3次作业,c语言
    第二次作业
    黄义方 作业4
    课堂作业
    第三次作业
  • 原文地址:https://www.cnblogs.com/MayGarden/p/1629620.html
Copyright © 2011-2022 走看看