您的位置:程序门 -> vc/mfc -> 进程/线程/dll



请教一个dll中导出头文件的问题,谢谢!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请教一个dll中导出头文件的问题,谢谢!
发表于:2008-01-11 14:05:50 楼主
请教一个关于dll的问题?

/***********test1.h*****************/

class   test1{
public:
test1();
~test1();

void   displaytest1();
};

/**********test1.cpp*****************/
#include   <iostream>
using   namespace   std;

#include   "test1.h"

test1::test1()
{

}

test1::~test1()
{

}

void   test1::displaytest1()
{
cout < <"test1" < <endl;
}

下面是我的dll的头文件
/************dlltest.h***********/
#ifdef   dll1_api
#else
#define   dll1_api   _declspec(dllimport)
#endif

#include   "test1.h"

class   dll1_api   dlltest{
public:
dlltest();
~dlltest();
void   displaydlltest();
void   displaydlltest1();

private:
test1   m_test1;
};

/***********dlltest.cpp***********/
#define   dll1_api   _declspec(dllexport)

#include   <iostream>
using   namespace   std;

#include   "dlltest.h"

dlltest::dlltest()
{

}

dlltest::~dlltest()
{

}

void   dlltest::displaydlltest()
{
cout < <"dlltest" < <endl;
}

void   dlltest::displaydlltest1()
{
m_test1.displaytest1();
}

我使用如下代码来使用这个dll
#include   <iostream>
using   namespace   std;
#include   "dlltest.h"

void   main()
{
dlltest   test;
test.displaydlltest();
  test.displaydlltest1();
char   a;
cin> > a;
}

编译时提示找不到"test1.h",如果我把test1.h添加至测试程序中就可以解决,我的问题是这种情况下是不是必须把test1.h
提供给dll的使用者,如果这样的话感觉挺别扭的,我只想提供dlltest.h,dlltest.lib   dlltest.dll
请问如果想只提供这三个文件该如何解决?我不想把所有的类定义都放在dlltest.h中,所以这种方法就不要说了,谢谢各位!
发表于:2008-01-11 14:29:071楼 得分:0
感觉你想让其它人使用你的test1类的功能
又不想让别人看到你的test1类的结构

可以只让你的dll输出函数      
在输出函数的内部实现中自己使用test1
这样就不用公开test1的结构了
发表于:2008-01-11 21:55:532楼 得分:0
既然你导出类,就有义务提供类定义的头文件
发表于:2008-01-11 23:32:163楼 得分:0
...貌似我语文学的不好没看懂   lz的意思     dll导出类必须要导出函数定义接口用户才能知道,也就是那个.h文件
发表于:2008-01-12 09:47:044楼 得分:0
用dll导出类,不是一个很好的设计。
用lib


快速检索

最新资讯
热门点击