[Solved] How to pass in a 1D array of strings into cpp addin

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

[Solved] How to pass in a 1D array of strings into cpp addin

Post by saleem145 »

Hello,

Stuck again!!

How do I pass in an array of strings as an input to one of my functions??

Specifically what should the function prototype be and what goes into the idl. I tried using Sequence< OUString const & > with no luck.

Thanks a ton for your help!!

Saleem
Last edited by saleem145 on Sun Jul 15, 2012 1:53 pm, edited 2 times in total.
OpenOffice 3.4.0
Mac OS X 10.5.8
User avatar
Charlie Young
Volunteer
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: How to pass in a 1D array of strings into cpp addin

Post by Charlie Young »

saleem145 wrote:Hello,

Stuck again!!

How do I pass in an array of strings as an input to one of my functions??

Specifically what should the function prototype be and what goes into the idl. I tried using Sequence< OUString const & > with no luck.

Thanks a ton for your help!!

Saleem
I hadn't tried this yet, so it gave me a chance to learn something.

Once again, add-in functions use two dimensional arrays, but that presents no problem because we can just have a two dimensional array with one column.

I made a function that accepts an array of strings (assuming one column), then reverses each string and returns the reversed array. In the idl it looks like

Code: Select all

 sequence< sequence< string > > reversestrings([in] sequence< sequence< string > > inString);
Now, after compiling the .idl, and generating the .rdb and the c++ headers, we find that in the header file that the function prototype does expect OUStrings, so our function looks like

Code: Select all

Sequence <Sequence< OUString >> SAL_CALL MyService1Impl::reversestrings(Sequence <Sequence< OUString >> const & inString )
		throw (RuntimeException)
{
	long n = inString.getLength();
	long i;

	Sequence <Sequence< OUString >> reversedstrings(n);
	
	for(i = 0;i < n;i++)
	{
		reversedstrings[i] = Sequence<OUString>(1);
		reversedstrings[i][0] = oureverse(inString[i][0]);
	}

	return reversedstrings;
}
Where to teach a bit about manipulating OUStrings, we reverse them with

Code: Select all

OUString oureverse(OUString s)
{
	OUString r;
	r = OUString();
	long i;

	for(i = s.getLength() - 1;i >= 0; i--)
	{
		r += OUString(s[i]);
	}
	return r;
}
I think you can handle the CalcAddin.xcu and such.
Apache OpenOffice 4.1.1
Windows XP
Post Reply