After testing the CImage code, I found development of a simple COM class implementation to be fairly straightforward. I used the Microsoft ATL (Active Template Library) to create the COM class, since it has good support for creating lightweight controls, and it comes with a number of wizards to generate the skeleton code that every COM class needs. I wanted to be able to use the COM class from scripting languages like VBScript or JavaScript, so I gave the class an automation-derived interface. To keep the code simple I included just a single method in the interface (see Listing 2, DIBToGif.idl). Finally, being performance conscious, I decided that the object should support the apartment-threading model.
Using the apartment-threading model means that an object server can support many objects, and that each object will be accessed by its own thread. So individual objects need not be concerned with threading or concurrency issues, but global or static data in the object server must be thread-safe. It soon became apparent that the old GIF code needed to be updated, so I removed all static data and made it per-instance data of the CImageGif class. I ran into another problem due to an aggressive optimization by the ATL wizard-generated project. A default option causes the C runtime library not to get linked in. In a lot of cases the C runtime isn't needed, and it can add 30 Kb to each COM object's size. Since some ActiveX controls must be transmitted over the Internet, DLL size is very important. But my control was only to be used on the server, so I could afford to link in the C runtime library. An added advantage of this decision was that it allowed me to use C++ exception handling and the STL (Standard Template Library).
Using the DIBToGif Control
The completed COM object can be used from both early and late bound languages, such as Visual Basic and VBScript respectively. (Visual Basic can also be used as a late-bound language.) Early bound languages will need a reference to the control's type library, but late bound languages will not. See Listing 3, test.vbs, for an example use of the DIBToGif control with Windows Scripting Host.