游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4191|回复: 14

dll 中输出类 必须有 lib么??

[复制链接]

3

主题

72

帖子

72

积分

注册会员

Rank: 2

积分
72
发表于 2006-4-14 11:09:00 | 显示全部楼层 |阅读模式
网上查了半天。
发现想要在dll中输出类, 就需要在工程中包含一个 lib才行。
没有不用包含lib的方法么?

14

主题

245

帖子

256

积分

中级会员

Rank: 3Rank: 3

积分
256
QQ
发表于 2006-4-14 12:13:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

有,看看OGRE里的RenderEngine是如何处理Dx和OGL的.就知道怎么做了.

3

主题

72

帖子

72

积分

注册会员

Rank: 2

积分
72
 楼主| 发表于 2006-4-14 12:45:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

简单给讲两句贝。

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2006-4-15 00:08:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

现实链接即可。使用lib是隐士链接。

3

主题

72

帖子

72

积分

注册会员

Rank: 2

积分
72
 楼主| 发表于 2006-4-15 18:31:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

现实链接即可。使用lib是隐士链接。

输出类 而不是函数。

你可以试一下,调用类中的函数,会有连接的错误的。

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2006-4-16 04:19:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

我现在的工程就是这样做的,没有问题。建议你好好学习windows dll的基本知识。

3

主题

72

帖子

72

积分

注册会员

Rank: 2

积分
72
 楼主| 发表于 2006-4-17 11:52:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

So far, I spoke of using functions, but hey, what about using classes exported from a DLL? Well, in the case of implicitly linked DLLs, there is no difference at all. But what about loading DLLs explicitly and using the exported classes? Well, under normal circumstances, it cannot be done, but I wrote this article not to explain to you why it cannot be done, but to give you an idea as to how you can do it. That's right!! Using exported classes by loading a DLL using a LoadLibrary() call.

楼上的哥们,你没明白我在说什么。

http://www.codeproject.com/dll/classesexportedusingLL.asp

好像需要一个注册。。。。

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2006-4-17 14:59:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

在你的 dll 中暴露一个创建 class object 的函数,在引用的工程里加入 class 的 header, 怎么会不行呢??? COM 就是这种工作方式,难道你这就不成立了吗?

3

主题

72

帖子

72

积分

注册会员

Rank: 2

积分
72
 楼主| 发表于 2006-4-17 17:17:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

简单的贴点代码,请指教一下啦。

首先输出一个类
// mydll.h

class MyDll
{
public:
  int age;
public:
  void Print();
}

MyDll * CreateMyDll();
void DelMyDll();

以下是一个main函数
//main.cpp

#include <windows.h>
#include "mydll.h"

HINSTANCE hModule;

MyDll * g_MyDll;

typedef MyDll *(* CREATE)();

CREATE Create;

int main()
{
   hModule = LoadLibrary( "mydll.dll" ) ;

  Create = (CREATE)GetProcAddress( hModule, "CreateMyDll");

  g_MyDll = Create();

g_MyDll-&gtrint();

}

这样的话在编译的时候就会如下的错误(当然前提是不包含lib)。
请看。

error LNK2001: unresolved external symbol "public: void __thiscall MyDll:rint(void)"

因为无法获得类中的函数的地址之类的信息而无法连接了。

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2006-4-18 10:37:00 | 显示全部楼层

Re:dll 中输出类 必须有 lib么??

在类的声明加上:
_declspec(dllexport)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-24 11:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表