1 新建控制台程序MyDllTest
2 在解决方案里面新建MyDll动态链接库
3 在动态链接库里面新建类CMath,
#pragma once
class _declspec(dllexport) CMath
{
public:
int Add(int a, int b);
int Sub(int a, int b);
};
#include "pch.h"
#include "CMath.h"
int CMath::Add(int a, int b)
{
return a+b;
}
int CMath::Sub(int a, int b)
{
return a-b;
}
4 在MyDllTest中引入MyDll,修改MyDllTest.cpp
#include <iostream>
#include "../MyDll/CMath.h"
int main()
{
CMath math;
std::cout << math.Add(4, 5) << std::endl;
}
5 运行即可