[Solved] How does XScript::invoke work

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] How does XScript::invoke work

Postby mangesh » Mon Feb 11, 2013 11:06 am

I have added the following application level macro to add two numbers using OOBasic IDE in My macros and dialogs section. This macro is added to the CalcLib/Module1.
Code: Select all   Expand viewCollapse view
Function UGADD( int1 as Integer , int2 as Integer) as Integer

Dim total as Integer
total =  int1 + int2
UGADD = total

End Function


I call the macro from an external C++ application using the following code

Code: Select all   Expand viewCollapse view
           Any aCtx;
            aCtx <<= OUString(); // This indicates OOoBasic script.
            Reference <XInterface> iFactory = rOfficeServiceManager->createInstance(
                                                    OUString( RTL_CONSTASCII_USTRINGPARAM(
                                                    "com.sun.star.script.provider.MasterScriptProviderFactory" )));

           
            if ( iFactory.is() )
            {
                Reference< XScriptProviderFactory > xFactory(iFactory, UNO_QUERY );
                Reference<XScriptProvider> xScriptProvider = xFactory->createScriptProvider(aCtx);
                       
                if ( !xScriptProvider.is() )
                {
                    printf("ExecuteOOoBasicCommand() Failed to create ScriptProvider");
                    return 1;
                }

                Reference<XScript> xScript = xScriptProvider->getScript(OUString( RTL_CONSTASCII_USTRINGPARAM                         ("vnd.sun.star.script:CalcLib.Module1.UGADD?language=Basic&location=application")));
           
               
                if ( !xScript.is() )
                {
                    printf("ExecuteOOoBasicCommand() Failed to obtain XScript");
                    return 1;
                }
               
                Sequence< Any  > inArgs(2);
                               
                Any aInt1 , aInt2;
                sal_Int32 i = 24, j = 26;
                aInt1 <<= i; 
                aInt2 <<= j;               

                inArgs.getArray()[0] = aInt1; // Input1 is 24
                inArgs.getArray()[1] = aInt2; // input2 is 26
               

                Sequence< Any > outArgs;               
                Sequence< sal_Int16 > outIndex;

                xScript->invoke(inArgs,outIndex,outArgs);     

               
                sal_Int32 out1 = 0, out2 = 0;
                sal_Int32 in1= 0, in2 = 0;
                Any result;

                sal_Int32 len = outArgs.getLength();
                sal_Int32 num = outIndex.getLength();
                sal_Int32 num1 = inArgs.getLength();

                sal_Int16 val1 = 0, val2 = 0;

                inArgs[0] >>= in1;  // This value is 24 as above
                inArgs[1] >>= in2;  // This value is 26 as above

                outArgs[0] >>= out1; // This value is 24
                outArgs[1] >>= out2; // This value is 24
                               
                outIndex[0] >>= val1; // This value is 0
                outIndex[1] >>= val2; // This value is 0
               
                sal_Int32 retVal;
               
                if( outArgs.getArray()[0] >>= retVal ) // This is incorrectly returned as the first input value.
                {
                    printf( "int successfully extracted %d!\n"  , retVal );
                }

            }


I need help in getting the output value from this call. I checked out the information at the following link,
http://www.openoffice.org/api/docs/comm ... cript.html

But I cant get the above working. Please help me in getting this sorted out.

thanks
Mangesh
Last edited by mangesh on Mon Feb 11, 2013 2:22 pm, edited 1 time in total.
OpenOffice3.4.0 Win7 x64.
mangesh
 
Posts: 26
Joined: Tue Aug 21, 2012 10:48 am

Re: How does XScript::invoke work

Postby Villeroy » Mon Feb 11, 2013 1:11 pm

http://www.openoffice.org/api/docs/comm ... tml#invoke
I'd suspect that it works exactly as documented. The method takes exactly one URL string and 3 arrays as arguments. The second array has short integer indices. Do not expect that anybody will debug your code. This is entirely your job.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28431
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How does XScript::invoke work

Postby hanya » Mon Feb 11, 2013 1:42 pm

Simply keep the return value of the invoke method.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: How does XScript::invoke work

Postby mangesh » Mon Feb 11, 2013 2:22 pm

Hi Hanya,
I think I missed the return from the invoke. I was looking for the result in the outParams.
thanks for pointing this out.

regards
Mangesh
OpenOffice3.4.0 Win7 x64.
mangesh
 
Posts: 26
Joined: Tue Aug 21, 2012 10:48 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest