Hi Thomas,
I have taken the time to put a rudimentary C++ example together that
uses the prei-installed GetProductname macro and gets its return value
to insert the string into a freshly opened document.
Note that I have cut done the complete thing and left out all kinds of
checks (for NULL etc.), so that readers don't get lost searching for
the important parts.
<code>
#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
#include <com/sun/star/script/provider/XScriptProvider.hpp>
#include <com/sun/star/script/provider/XScript.hpp>
using namespace std;
using namespace rtl;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::script::provider;
/* This is a small code snippet just to show how to call macros and
receive their return values
(which is not possible with the dispatch framework) using the new
Scripting Framework interfaces.
It uses the StarBasic GetProductname function coming with every
OOo/SO version to print out the product name.
ATTENTION: No error checking or handling is done, please check the
IDL Reference to see what exceptions can occur.
*/
int SAL_CALL main( int argc, char **argv )
{
Sequence <Any> outparam;
Sequence <sal_Int16> indexes;
OUString pname;
Reference< XComponentContext > xContext( ::cppu::bootstrap() );
Reference< XMultiComponentFactory > xServiceManager(
xContext->getServiceManager() );
Reference < com::sun::star::frame::XComponentLoader > xComponentLoader(
xServiceManager->createInstanceWithContext(
OUString( RTL_CONSTASCII_USTRINGPARAM(
"com.sun.star.frame.Desktop" ) ),
xContext ), UNO_QUERY );
Reference< XComponent > xComponent( xComponentLoader->loadComponentFromURL(
OUString::createFromAscii("private:factory/swriter"),
OUString::createFromAscii("_blank") , 0,
Sequence < ::com::sun::star::beans::PropertyValue >() ) );
Reference < XScriptProviderSupplier > xScriptPS(xComponent, UNO_QUERY);
Reference < XScriptProvider >
xScriptProvider(xScriptPS->getScriptProvider(), UNO_QUERY);
Reference < XScript > xScript(xScriptProvider->getScript(
OUString::createFromAscii(
"vnd.sun.star.script:Tools.Misc.GetProductname?language=Basic&location=application")),
UNO_QUERY);
// call the pre-installed GetProductname function of the shared
Tools library inside the Misc module and extract OUString value from
the returned any
xScript->invoke(Sequence <Any>(), indexes, outparam) >>= pname;
// insert the returned string into the opened text document..
Reference < ::com::sun::star::text::XTextDocument >
xDoc(xComponent, UNO_QUERY);
Reference < ::com::sun::star::text::XText > xText(xDoc->getText(),
UNO_QUERY);
xText->setString(pname);
return 0;
}
</code>
2005/10/25, Thomas Schindl <[EMAIL PROTECTED]>:
> But I think if you are calling a OOBasic-Macro e.g. from Java
> you need to invoke the ScriptingFramework don't you?
>
> So maybe the snippet should deal with calling a Macro from some UNO-Binding
> e.g. C++, Java, Python, ... and fetching its return value.
>
> Tom
>
>
> > --- Ursprüngliche Nachricht ---
> > Von: "G. Jasper" <[EMAIL PROTECTED]>
> > An: [email protected]
> > Betreff: Re: [api-dev] Returnvalues from Macros
> > Datum: Mon, 24 Oct 2005 19:45:46 +0200
> >
> > Tom Schindl wrote:
> >
> > >-----BEGIN PGP SIGNED MESSAGE-----
> > >Hash: SHA1
> > >
> > >Matthias Benkmann wrote:
> > >
> > >
> > >>On 10/17/05, Alexander Peters <[EMAIL PROTECTED]> wrote:
> > >>
> > >>
> > >>
> > >>>Hello!
> > >>>I use OLE to connect to OpenOffice.org Writer and want to get
> > >>>Returncodes from Macros which i execute with a dispatcher. How can i
> > >>>make this? Or is there an other way to execute macros to get a
> > >>>returnvalue? Any Codesnip in any language will help me.
> > >>>
> > >>>
> > >>If you don't need compatibility with versions prior to 2.0, you can
> > >>use the Scripting Framework (Developer's Guide chapter 18).
> > >>
> > >>The involved services and interfaces are
> > >>
> > >>The following code demonstrates the SFW:
> > >>
> > >>Sub Main
> > >> doc = ThisComponent
> > >> scriptProvider = doc.getScriptProvider()
> > >> script =
> >
> scriptProvider.getScript("vnd.sun.star.script:Standard.Module1.Foo?language=Basic&location=document")
> > >> retval = script.invoke(Array("Hallo World"), Array(), Array())
> > >> MsgBox(retval)
> > >>End Sub
> > >>
> > >>Function Foo(st as String) as String
> > >> MsgBox(st)
> > >> Foo = "Bye Bye"
> > >>End Function
> > >>
> > >>
> > >>Matthias
> > >>
> > >>---------------------------------------------------------------------
> > >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> > >>For additional commands, e-mail: [EMAIL PROTECTED]
> > >>
> >
> > >>This would be a great short code-snippet ;-)
> > >>Tom
> > >>
> > Tom, Matthias, Alexander,
> >
> > I suppose my example was too elaborate. The essence was in
> > calling the function, which returns a value, just as it does in
> > Matthias Benkmann's example.
> > But the code snippet can be much shorter, because you don't
> > need the scriptProvider at all:
> >
> > Sub shortMBNKMN
> > MsgBox Foo( "Hello World" )
> > End Sub
> >
> > Function Foo(st as String) as String
> > MsgBox(st)
> > Foo = "Bye Bye"
> > End Function
> >
> > This gives exactly the same result.
> >
> > Sincerely,
> > Gerrit Jasper
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
> --
> 10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
> +++ GMX - die erste Adresse für Mail, Message, More +++
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Best Regards
Christian Junker
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]