vs2015编译动态库,导出类,显示调用(三)
//动态库代码段
//.h
#ifndef HEADER_H
#define HEADER_H
#ifdef AFX_CLASS
#define AFX_EX_CLASS _declspec(dllexport)
#else
#define AFX_EX_CLASS _declspec(dllimport)
#endif
class AFX_EX_CLASS cls
{
public:
cls(int i, int j);
int add();
int getm();
int getn();
private:
int m;
int n;
};
#endif
//.cpp
#define AFX_CLASS
#include "head.h"
cls::cls(int i, int j)
{
m = i;
n = j;
}
int cls::add()
{
return m + n;
}
int cls::getm()
{
return m;
}
int cls::getn()
{
return n;
}
//-------------------------
//调用动态库代码段
#include "../../testdll/testdll/head.h"
#pragma comment(lib,"../../testdll/Debug/testdll.lib")
#include <iostream>
using namespace std;
int main()
{
cls *clsObj = new cls(2, 3);
int num = clsObj->add();
cout << "result = " << num << endl;
int m = 0,n = 0;
m = clsObj->getm();
n = clsObj->getn();
cout << "m = " << m << endl;
cout << "n = " << n << endl;
while (1);
return 0;
}
见代码:
https://github.com/18971492243/coding.git