Introduction
An .ocx file holds one or more controls, components that a program
creates through COM (the Component Object Model) and shows inside its own windows:
ActiveX controls, and the older OLE controls that they grew from. In the file it is a
DLL, a PE file
with the DLL flag set, so the headers, sections and tables are those of every other
PE file. The extension is a naming convention; nothing in the header marks a DLL as an
OCX.
A file dropped on any page opens in the explorer, with its structure, resources and code, like any PE file.
What is particular: a COM server
A control is an in-process COM server. Such a DLL exports a small, fixed set of functions, which Microsoft lists for a DLL that holds COM components:
| Export | What it does |
|---|---|
DllGetClassObject | Creates a class factory, the object that makes the control’s instances. |
DllCanUnloadNow | Says whether the DLL can safely be unloaded. |
DllRegisterServer | Creates the registry entries for all the classes in the file. |
DllUnregisterServer | Removes those entries. |
The registry entries are what let a program create the control from its class
identifier without knowing the file’s name: they tell COM which file serves the class.
DllRegisterServer returns S_OK when it succeeds, and
SELFREG_E_CLASS or SELFREG_E_TYPELIB when it could not
register all the classes or all the type libraries. If it fails, the state of the
registry for its classes is undefined.
The registration is called self-registration because the file does it for itself.
The tool that calls it is regsvr32.exe, which is run on the file.
The entry point works as in any DLL. All four exports are listed in the export directory, which the Exports page describes, so they can be read in the explorer.
Not described
Known, not yet covered
- Reference: the registry keys that registration writes, and the type library resource that many controls carry.
Links
Software
Reference
- DllRegisterServer function – what it does and its return values
- DLL Functions – the four exports of a COM server DLL, and registration with Regsvr32.exe, in the DirectShow documentation
- PE Format – Microsoft’s specification of PE32 and PE32+