VS2013中C++创建DLL导出class类

时间:2024-03-27 15:03:56

1.创建“Win32 Console Application”项目,命名为“ClassDllLib”,并在“Application type”中选择“DLL”

2.创建Student.h文件

#define DllExport __declspec(dllexport)

class DllExport Student
{
private:
int id;
public:
void setID(int id);
int getID();
};

3. 创建Student.cpp文件

#include "stdafx.h"
#include "Student.h"
int Student::getID()
{
return id;
}
void Student::setID(int _id)
{
id = _id;
}

4.创建“Win32 Console Application”项目,并在“Application type”中选择“Console application”。

5.在含有main函数的类中做如下调用:

#include "stdafx.h"
#include "Student.h"
#pragma comment(lib,"../Debug/ClassDllLib.lib") int _tmain(int argc, _TCHAR* argv[])
{
Student student;
student.setID(123);
printf("ID:%d",student.getID());
return 0;
}