C++ 组件

From Apache OpenOffice Wiki
Jump to: navigation, search
  • C++ 组件


C++ 组件的第一个步骤是定义与语言无关的接口,以便 UNO 对象可以与其他对象通信。组件的 IDL 规范将定义一个 my_module.XSomething 接口和实现此接口的两个老样式服务(如果使用新样式服务,示例将大致相同)。此外,称为 my_module.MyService2 的第二个服务将实现 com.sun.star.lang.XInitialization 接口,以便 MyService2 可以使用在运行时期间传送给它的参数进行实例化。

  #include <com/sun/star/uno/XInterface.idl>
  #include <com/sun/star/lang/XInitialization.idl>
 
  module my_module
  {
 
  interface XSomething : com::sun::star::uno::XInterface
  {
      string methodOne( [in] string val );
  };
 
  service MyService1
  {
      interface XSomething;
  };
 
  service MyService2
  {
      interface XSomething;
      interface com::sun::star::lang::XInitialization;
  };
 
  };

通过执行以下命令,此 IDL 将编译为生成二进制类型库文件(.urd 文件)。类型将被编译并合并到注册表 simple_component.rdb,该注册表将在以后链接到 OpenOffice.org。

 $ idlc -I<SDK>/idl some.idl
 $ regmerge simple_component.rdb /UCR some.urd


必须使用 cppumaker 工具将 IDL 映射到 C++:

 $ cppumaker -BUCR -Tmy_module.XSomething <officepath>/program/types.rdb simple_component.rdb


对于每个给定类型,都将生成一对头文件,即 .hdl.hpp 文件。为避免冲突,所有类型的 C++ 声明都位于 .hdl 中;所有的定义,如构造函数,都位于 .hpp 文件中。.hpp 可以包含在 C++ 中用到的任何类型。


下一步是实现其核心接口,以及使用或不使用 Helper 方法实现组件操作 component_getFactory()component_writeInfo()component_getImplementationEnvironment()


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