The Service Manager Component

From Apache OpenOffice Wiki
Jump to: navigation, search



Instantiation

The service manager is the starting point for all Automation clients. The service manager requires to be created before obtaining any UNO object. Since the service manager is a COM component, it has a CLSID and a programmatic identifier which is com.sun.star.ServiceManager. It is instantiated like any ActiveX component, depending on the language used:

  //C++
  IDispatch* pdispFactory= NULL; 
  CLSID clsFactory= {0x82154420,0x0FBF,0x11d4,{0x83, 0x13,0x00,0x50,0x04,0x52,0x6A,0xB4}}; 
  hr= CoCreateInstance( clsFactory, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&pdispFactory);

In Visual C++, use classes which facilitate the usage of COM pointers. If you use the Active Template Library (ATL), then the following example looks like this:

  CComPtr<IDispatch> spDisp;
  if( SUCCEEDED( spDisp.CoCreateInstance("com.sun.star.ServiceManager")))
  {
      // do something
  }

JScript:

  var objServiceManager= new ActiveXObject("com.sun.star.ServiceManager");

Visual Basic:

  Dim objManager As Object
  Set objManager= CreateObject("com.sun.star.ServiceManager")

VBScript with WSH:

  Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")

JScript with WSH:

  var objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager");

The service manager can also be created remotely, that is. on a different machine, taking the security aspects into account. For example, set up launch and access rights for the service manager in the system registry (see DCOM).

The code for the service manager resides in the office executable soffice.exe. COM starts up the executable whenever a client tries to obtain the class factory for the service manager, so that the client can use it.

Registry Entries

For the instantiation to succeed, the service manager must be properly registered with the system registry. The keys and values shown in the tables below are all written during setup. It is not necessary to edit them to use the Automation capability of the office. Automation works immediately after installation. There are three different keys under HKEY_CLASSES_ROOT that have the following values and subkeys:

Key Value
CLSID\{82154420-0FBF-11d4-8313-005004526AB4} "StarOffice Service Manager (Ver 1.0)"
Sub Keys
LocalServer32 "<OfficePath>\program\soffice.exe"
NotInsertable
ProgIDcom.sun.star.ServiceManager.1 "com.sun.star.ServiceManager.1"
Programmable
VersionIndependentProgID "com.sun.star.ServiceManager"


Key Value
com.sun.star.ServiceManager "StarOffice Service Manager"
Sub Keys
CLSID "{82154420-0FBF-11d4-8313-005004526AB4}"
CurVer "com.sun.star.ServiceManager.1"


Key Value
com.sun.star.ServiceManager.1 "StarOffice Service Manager (Ver 1.0)"
Sub Keys
CLSID "{82154420-0FBF-11d4-8313-005004526AB4}"


The value of the key CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\LocalServer32 reflects the path of the office executable.

Or, copy the following lines to your editor, edit the path to soffice.exe in the second line, and save and use it as a .reg file.


REGEDIT4

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}] @="\"StarOffice Service Manager (Ver 1.0)\""

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\LocalServer32] @="G:\\...\\program\\soffice.exe"

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\NotInsertable]

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\ProgIDcom.sun.star.ServiceManager.1] @="com.sun.star.ServiceManager.1"

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\Programmable]

[HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\VersionIndependentProgID] @="com.sun.star.ServiceManager"

[HKEY_CLASSES_ROOT\com.sun.star.ServiceManager] @="StarOffice Service Manager"

[HKEY_CLASSES_ROOT\com.sun.star.ServiceManager\CLSID] @="{82154420-0FBF-11d4-8313-005004526AB4}"

[HKEY_CLASSES_ROOT\com.sun.star.ServiceManager\CurVer] @="com.sun.star.ServiceManager.1"

[HKEY_CLASSES_ROOT\com.sun.star.ServiceManager.1] @="StarOffice Service Manager (Ver 1.0)"

[HKEY_CLASSES_ROOT\com.sun.star.ServiceManager.1\CLSID] @="{82154420-0FBF-11d4-8313-005004526AB4}"


All keys have duplicates under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.

The service manager is an ActiveX component, but does not support self-registration. That is, the office does not support the command line arguments -RegServer or -UnregServer.

The service manager, as well as all the objects that it creates and that originate from it indirectly as return values of function calls are proper automation objects. They can also be accessed remotely through DCOM.


From UNO Objects to Automation Objects

The service manager is based on the UNO service manager and similar to all other UNO components, is not compatible with Automation. The service manager can be accessed through the COM API, because the service manager is an Active X component contained in an executable that is the OpenOffice.org. When a client creates the service manager, for example by calling CreateObject(), and the office is not running, it is started up by the COM system. The office then creates a class factory for the service manager and registers it with COM. At that point, COM uses the factory to instantiate the service manager and return it to the client.

When the function IClassFactory::CreateInstance is called, the UNO service manager is converted into an Automation object. The actual conversion is carried out by the UNO service com.sun.star.bridge.oleautomation.BridgeSupplier (see The Bridge Services). The resulting Automation object contains the UNO object and translates calls to IDispatch::Invoke into calls to the respective UNO interface function. The supplied function arguments, as well as the return values of the UNO function are converted according to the defined mappings (see Type Mappings). Returned objects are converted into Automation objects, so that all objects obtained are always proper Automation objects.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages