Difference between revisions of "Documentation/DevGuide/WritingUNO/C++/Create Instance with Arguments"
From Apache OpenOffice Wiki
< Documentation | DevGuide
| Line 9: | Line 9: | ||
If the service should be raised passing arguments through <idlm>com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext</idlm>() and <idlm>com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments</idlm>(), it has to implement the interface <idl>com.sun.star.lang.XInitialization</idl>. The second service <code>my_module.MyService2</code> implements it, expecting a single string as an argument. | If the service should be raised passing arguments through <idlm>com.sun.star.lang.XMultiComponentFactory:createInstanceWithArgumentsAndContext</idlm>() and <idlm>com.sun.star.lang.XMultiServiceFactory:createInstanceWithArguments</idlm>(), it has to implement the interface <idl>com.sun.star.lang.XInitialization</idl>. The second service <code>my_module.MyService2</code> implements it, expecting a single string as an argument. | ||
<!--[SOURCE:Components/CppComponent/service2_impl.cxx]--> | <!--[SOURCE:Components/CppComponent/service2_impl.cxx]--> | ||
| − | < | + | <syntaxhighlight lang="cpp"> |
// XInitialization implementation | // XInitialization implementation | ||
void MyService2Impl::initialize( Sequence< Any > const & args ) | void MyService2Impl::initialize( Sequence< Any > const & args ) | ||
| Line 29: | Line 29: | ||
} | } | ||
} | } | ||
| − | </ | + | </syntaxhighlight> |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Writing UNO Components]] | [[Category:Documentation/Developer's Guide/Writing UNO Components]] | ||
Latest revision as of 14:37, 24 December 2020
- Class Definition with Helper Template Classes
- Implementing your own Interfaces
- Providing a Single Factory Using a Helper Method
- Write Registration Info Using a Helper Method
- Provide Implementation Environment
- Implementing without Helpers
- Storing the Service Manager for Further Use
- Create Instance with Arguments
- Multiple Components in One Dynamic Link Library
- Building and Testing C++ Components
If the service should be raised passing arguments through createInstanceWithArgumentsAndContext() and createInstanceWithArguments(), it has to implement the interface com.sun.star.lang.XInitialization. The second service my_module.MyService2 implements it, expecting a single string as an argument.
// XInitialization implementation
void MyService2Impl::initialize( Sequence< Any > const & args )
throw (Exception)
{
if (1 != args.getLength())
{
throw lang::IllegalArgumentException(
OUString( RTL_CONSTASCII_USTRINGPARAM("give a string instanciating this component!") ),
(::cppu::OWeakObject *)this, // resolve to XInterface reference
0 ); // argument pos
}
if (! (args[ 0 ] >>= m_arg))
{
throw lang::IllegalArgumentException(
OUString( RTL_CONSTASCII_USTRINGPARAM("no string given as argument!") ),
(::cppu::OWeakObject *)this, // resolve to XInterface reference
0 ); // argument pos
}
}
| Content on this page is licensed under the Public Documentation License (PDL). |