Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
668 views
in Technique[技术] by (71.8m points)

windows - What does registering a DLL do?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When a DLL is registered, the DllRegisterServer method entry point in your DLL is invoked. Similarly, DllUnregisterServer is invoked when a DLL is unregistered.

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.

The end result of registering a DLL is that all of the CLSIDs for the components in the DLL are registered under HKEY_CLASSES_ROOTCLSID. This allows CoCreateInstance to find the correct server when instantiating COM objects from another DLL or application.

DllUnregisterServer will do the reverse, and remove all of the CLSIDs from the registry that were put in there by DllRegisterServer.

More general information about DllRegisterServer can be found here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...