Navigation:  Programming Cookbook > External Interfacing > External Callbacks >

Virtual Callbacks

Previous pageReturn to chapter overviewNext page

It is also possible to implement virtual callbacks in Dolphin, and this is how OLE COM servers are implemented. It is not necessary to understand the precise details of how the such callbacks are mapped to method invocations against Smalltalk objects, and indeed it rather complex, but a brief overview is provided below. To see how to implement a COM server object in practice take a look at the EnumRect and COM Random Stream samples.

Virtual callbacks are dispatched into the image by the VM sending a #comCallback:id:subid:withArgumentsAt:cookie message to the Processor object, as described in Callback Entry Points above. The Processor locates the appropriate COMObjectStub, of which there is one per COM server object (usually a COMInterfaceImp subinstance, though this is not mandatory), and forwards it a #callback:vfn withArgumentsAt: message that identifies the particular COMInterface, the member function of that interface which is being called, and the address on the machine stack of the arguments accompanying the call. The COMObjectStub then forwards on the message to the relevant COMInterface, which in turn forwards it as the appropriate method invocation, usually to the COM server object, although the basic IUnknown methods are implemented by the stub itself. This rather tortuous route allows each of the objects involved to override the default handling, and allows for a great deal of flexibility in determining which object actually implements a COM method.

In order to construct the actual method invocation message, the COMInterface uses its function table. The function table includes object which describe each of the methods in the interface and how they should be dispatched. The function table is constructed by the #defineFunctions method, which is normally auto-generated by the Active-X component wizard. The function objects include descriptions of the types of the arguments to be found on the machine stack, and this external type information is used to construct Smalltalk objects from the arguments passed on the machine stack. With the argument objects constructed the message is eventually delivered to the target COM server object by performing the selector associated with the function object.