给用户提供接口的时候应该至少有以下几个文件:
- ISample.h 提供给用户的接口头文件,里面应该有接口函数的定义,一般都是纯虚函数。
- SampleAPI.h 提供给用户的接口头文件,里面应该有DLL应用程序的入口点,以及ISample 对象的创建和析构。
- CSample.h 不提供给用户,一般继承自ISample 并且实现ISample 里接口函数的功能。
以下是一个简单的例子:
/*
* Author: zjt
*
* 功能:提供给用户的接口头文件
*/
#ifndef MY_ISAMPLE_H
#define MY_ISAMPLE_H
class ISample
{
public:
// Constructor
//
ISample(){};
// Destructor
//
virtual ~ISample(){};
// interface function
// return Computer name
virtual int GetComputerName(TCHAR* pComputerName,size_t name_size) = 0;
//interface function
//return System Directory
virtual int GetSysDirectory(TCHAR* pSysDirectory,size_t dir_size) = 0;
};
#endif
/*
* Author: zjt
*
* 功能:提供给用户的API头文件
* 注意:SAMPLE_EXPORTS 应该在工程->属性->预定义设置里
*/
#ifndef __SAMPLE_API_DLL__
#define __SAMPLE_API_DLL__
#include "ISample.h"
#ifdef SAMPLE_EXPORTS
#define SAMPLE_API __declspec(