windows 注册 DLL 有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/620858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does registering a DLL do?
提问by stimms
I know how to register dlls but I've never really been sure why I'm doing it or under what conditions a dll must be registered. Could somebody explain or point me to some documentation?
我知道如何注册 dll,但我从来没有真正确定我为什么要这样做或在什么条件下必须注册 dll。有人可以解释或指向我一些文档吗?
采纳答案by LeopardSkinPillBoxHat
When a DLL is registered, the DllRegisterServer
method entry point in your DLL is invoked. Similarly, DllUnregisterServer
is invoked when a DLL is unregistered.
注册DllRegisterServer
DLL 后,将调用 DLL 中的方法入口点。类似地,DllUnregisterServer
在取消注册 DLL 时调用。
As described in this MSDN article:
Instructs an in-process server to create its registry entries for all classes supported in this server module. If this function fails, the state of the registry for all its classes is indeterminate.
指示进程内服务器为此服务器模块中支持的所有类创建其注册表项。如果此函数失败,则其所有类的注册表状态都是不确定的。
For COM DLLs, you will need to implement your own DllRegisterServer
and DllUnregisterServer
entry point methods which do the registering/unregistering as appropriate. Example code for DllRegisterServer
can be found here.
对于COM DLL文件,你将需要实现自己DllRegisterServer
和DllUnregisterServer
切入点方法里面做了登记/注销适当。DllRegisterServer
可以在此处找到示例代码。
The end result of registering a DLL is that all of the CLSIDs for the components in the DLL are registered under HKEY_CLASSES_ROOT\CLSID
. This allows CoCreateInstance
to find the correct server when instantiating COM objects from another DLL or application.
注册 DLL 的最终结果是 DLL 中组件的所有 CLSID 都注册在HKEY_CLASSES_ROOT\CLSID
. 这允许CoCreateInstance
在从另一个 DLL 或应用程序实例化 COM 对象时找到正确的服务器。
DllUnregisterServer
will do the reverse, and remove all of the CLSIDs from the registry that were put in there by DllRegisterServer
.
DllUnregisterServer
将执行相反的操作,并从注册表中删除由DllRegisterServer
.
More general information about DllRegisterServer
can be found here.
DllRegisterServer
可以在此处找到有关的更多一般信息。
回答by Pontus Gagge
What is most commonly referred to as DLL registering is when it implements a COM object. regsvr32 ensures that an instance of the object can be created. When e.g. VBScript uses New or CreateObject(), the registration ensures that COM knows what DLL to load in order to make a new instance, whether by name or CLSID.
最常称为 DLL 注册的是它何时实现 COM 对象。regsvr32 确保可以创建对象的实例。例如,当 VBScript 使用 New 或 CreateObject() 时,注册可确保 COM 知道要加载哪个 DLL 以创建新实例,无论是按名称还是 CLSID。
See "the layman's explanation"for a (very) brief summary.
有关(非常)简短的摘要,请参阅“外行的解释”。
回答by Pontus Gagge
Simply see the source code of regsvr32.exe
简单看regsvr32.exe的源码