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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:07:19  来源:igfitidea点击:

What does registering a DLL do?

windowscomdll

提问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 DllRegisterServermethod entry point in your DLL is invoked. Similarly, DllUnregisterServeris invoked when a DLL is unregistered.

注册DllRegisterServerDLL 后,将调用 DLL 中的方法入口点。类似地,DllUnregisterServer在取消注册 DLL 时调用。

As described in this MSDN article:

这篇 MSDN 文章所述

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 DllRegisterServerand DllUnregisterServerentry point methods which do the registering/unregistering as appropriate. Example code for DllRegisterServercan be found here.

对于COM DLL文件,你将需要实现自己DllRegisterServerDllUnregisterServer切入点方法里面做了登记/注销适当。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 CoCreateInstanceto find the correct server when instantiating COM objects from another DLL or application.

注册 DLL 的最终结果是 DLL 中组件的所有 CLSID 都注册在HKEY_CLASSES_ROOT\CLSID. 这允许CoCreateInstance在从另一个 DLL 或应用程序实例化 COM 对象时找到正确的服务器。

DllUnregisterServerwill 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 DllRegisterServercan 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的源码