Why Self-Registering?
You have developed some ActiveX controls. If the user has to register your controls before they can
be used, they will feel inconvenienced. It is better to have the components register themselves. If you
use ATL to develop your ActiveX control, it comes with a self-registering capability automatically.
However, if you use MFC, the control is not self-registering by default. This article shows you how to
enable self-registering for MFC ActiveX controls.
What is Self-Registering?
Self-Registering means that the server enables the client to register and unregister the server at
run-time. In other words, the client who wants to use the DLL server will register it if the server is
enabled for self-registering. You don’t have to work with the Registry. A self-registering DLL server,
for example an ATL ActiveX control, exports two functions for registering and unregistering itself:
DllRegisterServer() and DllUnregisterServer(). They are called by an external
program.
The procedure is as follows:
- The client looks for the string
OleSelfRegister in the version information of
the server.
- If this string is found, the client registers the server using the pointer obtained from
DllRegisterServer() in the server.
- After using the server, the client calls
DllUnregisterServer() in the server
to unregister it.
When you create a MFC ActiveX control using VC++, the control is not self-registering by default.
To modify it to be self-registering, you need to edit the Version Information in the resource. However,
the resource editor does not let you do it. You have to open the .rc file and edit it manually. All
you have to do is to add:
VALUE "OLESelfRegister", "\0"
following
VALUE "ProductVersion", "1, 0, 0, 1\0"
After you edit, the version information block will look something like this:
VALUE "CompanyName", "MyCompany\0"
VALUE "FileDescription", "MyCtrl ActiveX Control Module\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", " MyCtrl \0"
VALUE "LegalCopyright", "Copyright (C) 2000\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", " MyCtrl.OCX\0"
VALUE "ProductName", " MyCtrl ActiveX Control Module\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
VALUE "OLESelfRegister", "\0"
Then you build the control again, you will get a self-registering ActiveX control.