为什么我们使用dll文件? [英] why do we use dll file?

查看:61
本文介绍了为什么我们使用dll文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解.dll文件?为什么我们需要使用它?

Im not quite understanding about .dll file ? why do we need to use it?

推荐答案

要将您的程序分解为更小,更易于管理的块,这些块可以由多个应用程序使用.

如果将应用程序作为一个EXE文件编写,则首先它将是一个大文件,其次,如果不将代码源实际复制到另一个应用程序,则该文件中的任何代码都无法在下一个应用程序中使用. br/>
假设您编写了一个非常有用的类表单来处理您的主要公司数据库.太好了-因此在您的下一个应用中,您想再次使用它.您复制代码,然后将其拍打到新项目中.很好-一切正常.您一次又一次地执行此操作.但是随后有人在第二个应用程序中发现了一个问题-它需要更改您的Wonder Class以修复它.你做什么工作?您是否仅在第二个应用程序中更改了副本?还是您要单独更新所有其他应用程序?如果第三个应用程序中存在其他问题,需要进行更改,该怎么办?突然,您将面临同一代码的10或12个不同且不兼容的版本-一切都开始成为一场噩梦.

相反,如果将您的类放在单独的DLL中,则其他所有类都可以引用它.并且只要您对应用程序2所做的更改不会影响其他应用程序所公开的功能,那么所有这些都可以使用.您只有一套代码,其他所有代码都会自动使用并有效地更新到最新版本,而无需任何工作,配置麻烦或任何其他事情!

将所有内容都保存在单个exe文件中是可以的,但这有点像汽车的早期历史:每个制造商对驾驶汽车需要使用什么控件以及应该在什么位置使用都有自己的想法.放置.慢慢地,他们全都移动以使用一组通用的控件:按定义顺序的一个轮子和三个踏板.
您能想象一下,如果有三个操纵杆和一个脚控制的转向杆,租一辆车会有什么乐趣?

那是因为他们将每辆车都视为一个单独的单元(一个EXE),而不是使用共同的功能(在DLL文件中).
To break your program up into smaller, more manageable chunks that can be used by more than one application.

If you write your application as one EXE file, then firsth it will be a single huge file, and secondly, none of the code in the file can be used in your next app without physically copying the code source from one to the other.

Suppose you write a really useful class form handling your main company database. It''s wonderful - so in your next app, you want to use it again. You copy the code, and slap it into the new project. Fine - it all works. You do it again, and again. But then someone finds a problem in the second app - and it needs a change in your wonder class to fix it. What do you do? Do you change just the copy in the second app? Or do you update all the other apps individually? What if there is a different problem in the third app which needs a different change? Suddenly, you are faced with 10 or twelve different and incompatible versions of the same code - and it all starts to be a nightmare.

If instead, you put your class in a separate DLL, all the others could refer to it. And provided that your changes for app 2 don''t impact on the functionality exposed for the others, it all works. You have a single set of code, which all the others automatically use and effectively get updated to the latest version of, without any work, or configuration hassle, or anything!

Keeping everything in a single exe is fine, up to a point, but it''s a bit like the early history of cars: every manufacturer had their own idea of what controls you need to use to drive a car, and where they should be placed. Slowly, they all moved to use a common set of controls: a wheel and three pedals in a defined order.
Can you imagine what fun it would be to hire a car if it had three hand levers and a foot controlled steering bar?

That''s because they considered each car as a separate unit (a single EXE) instead of using common features (in DLL files).


DLL文件的概念可轻松集成第三方库在应用程序中.

例如,如果我们要电视,请购买它,然后参阅指南了解如何使用它.然后,按照这些说明操作电视,并达到目的,而不用了解电视的功能,内部组件是什么,它们如何相互影响等.

同样,对于一组定义的功能,例如,我们希望将漂亮的图表合并到我们的应用程序中,但没有足够的想法和专业知识或时间来编写图表应用程序.

在这种情况下,可以使用开源,免费软件或商业软件来获取好的第三方库,然后通过阅读有关如何使用该库的文档,我们可以将图表合并到我们的应用程序中,甚至不知道图表是如何内部绘制的.

我们只关心库公开的公共方法,属性和事件. DLL文件很容易实现这一点.
DLL file concept enables easy integration of third party libraries in an application.

For example, if we want a TV, we purchase it and see the guide for the instructions on how to use it. Then using those instructions we operate the TV and our purpose is served, without knowing how the TV functions, what are the internal components, how they interact with each other etc.

Similarly, for a defined set of functionality, say, we want a nice chart to be incorporated in our application, but do not have enough idea and expertise or time to write a chart application.

In such case a good third party library can be taken either open source, freeware or commercial, then by reading the documentation on how to use the library, we can incorporate the charts in our application, without even knowing how the chart is drawn internally.

We are only concerned with the public methods, properties and events exposed by the library. This is easily facilitated by DLL files.


这篇关于为什么我们使用dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆