如何设计这个C++程序的API?
写完了C++应用程序的代码,现在要做一个API生成DLL,请问大家,该如何来设计这样的接口呢?
看了中科院分词程序的API接口代码,有初始化资源的接口,有分词函数的接口,有释放资源的接口。
自己来设计时就遇到问题了:
我的C++项目大致是这样的:读入帖子的编号、标题和内容,返回一个XML结果的字符串;
int _Process(const char* pInfoID, const char* pTitle, const char* pContent, char* pResult);
参数依次是 信息编号、标题、内容,最后的pResult是返回结果;
需要需要用户自己申请一段内存来存放返回结果;
看中科院分词的程序有初始化资源以及最后释放资源的接口,我的代码中也需要读入词典等内容,但这一块我就不知道如何设计了。
#pragma once#ifndef _TUIXINDLL_H_#define _TUIXINDLL_H_#include "commonpredefine.h"#include "cutwords.h"#include "encoding.h"#include "linkrule.h"#include "resmgr.h"#include "utf16manip.h"#include <time.h>CHarSetsEncoding CSEncoding; //编码转换的类;UTF16CutWords UTF16CWords; //切词的类,会读入词典的内容;int _Process(const char* pInfoID, const char* pTitle, const char* pContent, char* pResult);#endif /* _TUIXINDLL_H_ */