Navigation:  Programming Cookbook > Creating COM Components > Testing & Debugging > Debugging "In-image" >

Registering a Class Factory

Previous pageReturn to chapter overviewNext page

To make the COM subsystem aware of the components that a server can supply one must go through the process of registering class factory objects for each component.

Dolphin provides a standard class factory implementation as part of its COM framework (see COMClassFactory and subclasses), and this maintains its own register mapping COM’s class identifiers (CLSIDs) to the Dolphin class that implements that component.

Registering a class factory in Dolphin is a simple operation that is achieved by sending #registerClassFactory to one's COMInterfaceImp subclass, for example:

       COMRandomStream registerClassFactory


This need only be done once, as subsequently Dolphin will automatically register a class factory object for all previously registered COM classes on image start-up. Once this has been done, the running development system will have been registered as both the local and in-process server for that component, and COM will service instance creation requests using that server without reference to the registry. Hence, even without making any registry entries, one can now evaluate:

       r := IRandomStream new.


You might like to debug through this expression to see how Dolphin constructs a call to CoGetClassObject() that calls back into Dolphin to find the class factory we registered earlier. The first callback will be an IUnknown::AddRef(), then a call to IUnknown::QueryInterface() for IClassFactory, and so on. If you continue stepping through these you will be able to follow through the whole instance creation process on client and server sides, all implemented entirely in Smalltalk. This will give you a good understanding of this basic functionality of Dolphin’s COM framework.

For debugging purposes, the client code could just be some workspace test expressions, for example:

       r := IRandomStream new.        "Creates object via COM, but in-image/process"

       r next.

       r lowerBound: 10.

       r next.



Ideally, though, we would recommend the construction of suitable SUnit TestCases to provide repeatable regression tests. SUnit TestResources can be used to ensure that the correct environment for in-image running is prepared (essentially just that a class factory is registered).