Component Object Model - nsgomez/gzcom-dll GitHub Wiki

The Component Object Model (COM) is a programming model introduced by Microsoft where all objects in a codebase are derived from a common "unknown" interface, intended to facilitate the use of objects without needing to know their internal representation. More technical and historical information about the COM can be found on Wikipedia's article.

In the COM, objects are identified by class IDs (CLSIDs) and implement interfaces that are identified by interface IDs (IIDs).

SimCity 4 uses a derivative of the COM internally called the GZCOM (short for Gonzo COM, from the Rizzo-Gonzo framework). The main difference between the COM and the GZCOM is that the GZCOM uses regular 32-bit integers for class and interface identifiers, while Microsoft's COM uses full GUIDs.

As such, SC4's internal objects implement a common interface, cIGZUnknown:

class cIGZUnknown
{
    public:
        virtual bool QueryInterface(uint32_t riid, void** ppvObj) = 0;
        virtual uint32_t AddRef(void) = 0;
        virtual uint32_t Release(void) = 0;
};
  • QueryInterface acts as a cast to a different interface based on the interface ID (riid) passed in. If the class implements the desired interface, *ppvObj will be a pointer to that interface, a reference is automatically added, and the method will return true. Otherwise, false is returned.
  • AddRef adds a reference to the object and returns the new reference count.
  • Release removes a reference to the object and returns the new reference count. If the reference count is zero, the object is deleted except for GZCOM Directors. Paul Pedriana's reference code cites the reason for this as being that "directors are NOT stack objects but are usually statically defined."