(1) 在DLL工程中 point 类的头文件point.h中加入以下语句
//文件名:point.h,point类的声明
#ifndef POINT_H
#define POINT_H
#ifdef DLL_FILE
class _declspec(dllexport) point//导出类point
#else
class _declspec(dllimport) point//导入类point
#endif
{
//...声明类point 的成员变量和成员函数
}
(2) 在DLL工程中 point 类的实现文件point.cpp开头中加入语句如下:
#ifndef DLL_FILE
#define DLL_FILE
#endif
#include ...
(3) 在调用DLL导出类的函数所在文件的开头加上
#include "point.h"
#pragma comment(lib,"dllTest.lib)"
//切记,不能#define DLL_FILE
这样,经过(1)(2)(3),因为在DLL的类实现代码中定义了宏DLL_FILE,故在DLL的类实现中所包含的类声明实际上为:
class _declspec(dllexport) point;//导出类
而调用DLL的应用工程中没有定义DLL_FILE,故其包含point.h后引入的类声明为:
class _declspec(dllimport) point;//导入类