Next: Using GNAT COM objects as Distributed COM objects, Previous: InProc container implementation, Up: Creating COM objects with GNAT [Contents][Index]
LocalServers (Exe’s containing COM objects) must handle three command
line parameters, /Embedding, /RegServer, and /UnregServer.
The LocalServer is called with /Embedding when the operating system
needs to create COM objects that are contained in the server. It may
also be used form the command line to pre-load the container in memory
so that future requests of clients to create COM objects will be
quicker. When embedding, the Win32 API CoInitialize is called to load
the COM environment. Then a class factory for each COM object type that
can be created is registered with the operating system using the
CoRegisterClassObject API call. In order for the server to wait for the
COM objects to be used and to later shutdown it starts up a Win32
message loop. Upon receiving notice that the server is no longer needed
(all the COM objects it created were destroyed and there are no server
locks), the messag loop exits and the API function
CoUnregisterClassObject is called for each factory that was
registered. The application then completes after calling the
CoUnitialize API function to shutdown the COM environment.
When started with /RegServer or /UnregServer then same
process used in the InProc implementation is used to register or
unregister the type libraries and NT registry entries.
See the gnatexample-exe.adb file for a complete example.