Code: Select all
Function UGADD( int1 as Integer , int2 as Integer) as Integer
Dim total as Integer
total = int1 + int2
UGADD = total
End Function
Code: Select all
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 );
}
}
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