0x00 引言
再简单的事情,也需要有人去做。
0x01 Cpp工程
CppMath.h
#pragma once
#include <stdexcept>
class CppMath
{
public:
double Add(double arg1,double arg2);
};
CppMath.cpp
#pragma once
#include "CppMath.h"
double CppMath::Add(double arg1,double arg2)
{
return arg1+arg2;
}
0x02 CLR Wrapper工程
CLRWrapper.h
#pragma once
#include "CppMath.h"
using namespace System;
namespace CLRWrapper {
public ref class CppMathWrapper
{
public:
//ctor
CppMathWrapper();
//Methods
double Add(double arg1,double arg2);
private:
CppMath *cppMath;
};
}
CLRWrapper.cpp
#include "stdafx.h"
#include "CLRWrapper.h"
#include "CppMath.cpp"
CLRWrapper::CppMathWrapper::CppMathWrapper()
{
cppMath = new CppMath();
}
double CLRWrapper::CppMathWrapper::Add(double arg1,double arg2)
{
return cppMath->Add(arg1,arg2);
}
添加头文件依赖
Properties –> Configuration Properties –> C/C++ –> Additional Include Directories
0x03 C#工程
添加引用
prograss.cs
CppMathWrapper wrapper = new CppMathWrapper();
Console.WriteLine(wrapper.Add(1.4, 2.7));
Console.ReadLine();
0x04 UPDATE
2019-02-18