现有两个类,我不想让别人看到它们的实现部分,只提供几个函数给用户调用..期间遇到了点问题:
两个类CMyBitmap,CEngine..
下面是类CMyBitmap定义.h文件和实现.cpp文件///////////////////////////////////
//Bitmap.h 类CMyBitmap定义文件
#ifndef BITMAP_H
#define BITMAP_H
#include <windows.h>
class CMyBitmap
{
public:
void _declspec(dllexport) Func1();
};
#endif
///////////////////////////////////
//Bitmap.cpp 类CMyBitmap实现文件
#include "Bitmap.h"void CMyBitmap::Func1()
{
MessageBox(NULL, "MessageBox From CMyBitmap", "", MB_OK);
}
下面是类CEngine定义.h文件和实现.cpp文件///////////////////////////////////
//Engine.h 类CEngine定义文件
#ifndef ENGINE_H
#define ENGINE_H#include "Bitmap.h" class CEngine
{
public:
void _declspec(dllexport) Func2();
};#endif
///////////////////////////////////
//Engine.h 类CEngine定义文件
#include "Engine.h"void CEngine::Func2()
{
MessageBox(NULL, "MessageBox From CEngine", "", MB_OK);
}问题是,我只想给用户Engine.h, Engine.lib, Engine.dll这三个文件让用户使用,当用户想用类CMyBitmap时,会提示类未定义,必须要把Bitmap.h一块给用户才行,有什么办法把Bitmap.h内容包含在Engine.h里吗,我可能要做好多类,不可能把每个类的.h文件都给用户,这样太麻烦,有什么办法把它们都放一个.h文件,用的时候只要include这个文件就好了..希望我把问题描述清楚了!!!~~~ 谢谢大家!
两个类CMyBitmap,CEngine..
下面是类CMyBitmap定义.h文件和实现.cpp文件///////////////////////////////////
//Bitmap.h 类CMyBitmap定义文件
#ifndef BITMAP_H
#define BITMAP_H
#include <windows.h>
class CMyBitmap
{
public:
void _declspec(dllexport) Func1();
};
#endif
///////////////////////////////////
//Bitmap.cpp 类CMyBitmap实现文件
#include "Bitmap.h"void CMyBitmap::Func1()
{
MessageBox(NULL, "MessageBox From CMyBitmap", "", MB_OK);
}
下面是类CEngine定义.h文件和实现.cpp文件///////////////////////////////////
//Engine.h 类CEngine定义文件
#ifndef ENGINE_H
#define ENGINE_H#include "Bitmap.h" class CEngine
{
public:
void _declspec(dllexport) Func2();
};#endif
///////////////////////////////////
//Engine.h 类CEngine定义文件
#include "Engine.h"void CEngine::Func2()
{
MessageBox(NULL, "MessageBox From CEngine", "", MB_OK);
}问题是,我只想给用户Engine.h, Engine.lib, Engine.dll这三个文件让用户使用,当用户想用类CMyBitmap时,会提示类未定义,必须要把Bitmap.h一块给用户才行,有什么办法把Bitmap.h内容包含在Engine.h里吗,我可能要做好多类,不可能把每个类的.h文件都给用户,这样太麻烦,有什么办法把它们都放一个.h文件,用的时候只要include这个文件就好了..希望我把问题描述清楚了!!!~~~ 谢谢大家!
#include <windows.h>后,大量的东西你就可以使用了。
一,就是传统的com.二,以c++形式提供我举个例子,伪代码。
头文件IYourInterface_h.hclass IYourInterface()
{
virtual void function1() = 0;
}IYourInterface* CreateInterface();
void DeleteInterface(IYourInterface*pt);
--------
实现文件头文件YourImp.h
class CYourImpl : public IYourInterface
{
virtual void function1() ;
CEngine *pEnqine;
}
---------
实现文件YourImp.cpp
#include YourImp.h
#include "enqine.h"//你的实现类
.....
void CYourImpl::function1()
{
if(!pEnqine)
pEnqine = new CEngine(); pEnqine->Func2();
}-----------------
用户的应用中使用的时候,只需要inluce IYourInterface_h.h
并IYourInterface* pT = CreateInterface();
pT->function1();//实际上会调用你的Func2()
用完
DeleteInterface(pT);------------------
很显然你提供给用户的头文件IYourInterface_h.h
不涉及任何你需要的实现文件,故不会有任何问题。
建议采用7楼的做法。把要提供的类换成接口,但客户端想用那个接口想提供的接口时,直接QueryInterface就可以的。