UWP C# 调用 C++/CX

创建一个UWP项目

然后创建一个通用C++运行时项目

右键点击C++项目,添加一个C++类

 

头文件.h

--------------------------------------------

#pragma once

namespace Test
{
  public ref class MyMath sealed
  {
    public:
      int add(int a, int b);
  };
}

 

源文件.cpp

-------------------------------------------------------------------------------------

#include "pch.h"
#include "MyMath.h"

namespace Test
{

  int MyMath::add(int a, int b)
  {
    return a + b;
  }

}

 

 

uwp C#项目的引用

------------------------------------------------------------------------

MyMath math = new MyMath();
this.sum.Text = math.add(200, 300).ToString();

 

posted @ 2021-01-22 13:40  MaxBruce  阅读(192)  评论(0编辑  收藏  举报