computing: software: programming: Windows: ActiveX
Although ActiveX is more widely known for its use (some would say misuse) in embedding (MSIE-only) applets within web pages, it is actually more useful for regular Windows application programming.
Note: Does anyone know if there is anything comparable in the open-source world? I have heard mention of many data-exchange formats which sound as though they might be similar, but I have not progressed far enough in my understanding to determine whether they actually are. --Woozle 20:08, 29 January 2007 (EST)
ActiveX Application Programming
What ActiveX provides is an API for dynamically-loaded code libraries (which can be in either DLL or EXE form) to use to announce the function calls which they make available. This API greatly improves integration with integrated development environments; for example, Visual Basic 6 not only allows the human programmer to browse available ActiveX libraries and view the functionality available from them, but also extends its auto-fill capabilities to include the various identifiers (method names, global names, enums) exported by referenced ActiveX libraries as if they were part of the local Visual Basic code within the same project.
When writing an ActiveX module (or "an ActiveX" for short), you have to choose whether to make it an "ActiveX EXE", "ActiveX DLL", or "ActiveX Control". The EXE version has more options for threading, and there may be other differences as well. The Control type is intended for creating controls to place on forms, and in fact all of the controls available within VB, beyond the initial default set, are provided as ActiveX modules.
Once the module is compiled and running, it will appear in the list of "References" if it is an EXE or DLL, or the list of "Components" if it is a Control. These dialogs are found under the "Project" menu in VB6; in MS Access 97, they are found in the "Tools" menu but only when a code module is being edited.
Each ActiveX module has a file, a project name, and descriptive text associated with it. The list of ActiveX modules will show only the descriptive text, unless there is none in which case it will show the project name. (It is a good idea, therefore, to prefix the descriptive text with the project name, e.g. "MyProject: data services for doing stuff" rather than just "data services for doing stuff".) If the module is running within the VB IDE, rather than having been compiled to an EXE or DLL, the file's "name" will be that of the VB project file (e.g. MyProject.vbp). If you compile the project to a file, then VB will automatically "register" (see below) the compiled file for you so it will show up in the list.
Registering ActiveX Modules
There are two ways for other applications to become aware of the existence of an ActiveX module: (1) manual browsing, and (2) registration.
Many ActiveX modules are registered automatically by installer programs. VB6 (and presumably other ActiveX-capable IDEs) will automatically register ActiveX modules it compiles. Sometimes, however, you will need to be able to manually register (or un-register) an ActiveX module; this is done differently depending on what type of module you are dealing with:
- ActiveX DLLs: use the program RegSvr32.exe, which is provided as part of Windows 95, 98, 2000, and presumably later versions as well.
- ActiveX EXEs: use the /regserver and /unregserver command-line options
- Microsoft: How To Register and Unregister an Out-of-Process COM Component (ActiveX EXE)
- Note that Windows will prevent you from deleting an ActiveX EXE which is still being referenced by any other program, even if you have unregistered it. (This is probably because the EXE remains loaded in memory, and loaded executables can't be deleted.) Being referenced will not prevent an ActiveX EXE from being unregistered, and there will be no warning that it is still in use; apparently the "registration" process is something like adding the file to an in-memory listing (presumably based on data in the Windows Registry), but once a program actually connects to the ActiveX, it no longer needs the listing.