uno api problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

uno api problem

k.misha
Hi!

 

I have some problems using UNO API! I have this example:

 

Int x = 0;

Int y = 1;

Char * fontName = "Corbel";

Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);

Reference< XCell > rCell = rSpSheet->getCellByPosition(x, y);

Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);

 

OUString sstring = OUString(RTL_CONSTASCII_USTRINGPARAM(fontName));

xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontNam
e")), makeAny(sstring));

 

But when I look into a cacl document, there is wrong value in cell(0,1). I's
"Cor". But must be "Corbel".

 

Can you help me and show where I'm wrong?

 

Thanks.

 

 

Reply | Threaded
Open this post in threaded view
|

Re: uno api problem

Ariel Constenla-Haile-2
Hi k. misha,

On Thu, Apr 04, 2013 at 11:20:04AM +0300, k.misha wrote:

> Hi!
>
>  
>
> I have some problems using UNO API! I have this example:
>
>  
>
> Int x = 0;
>
> Int y = 1;
>
> Char * fontName = "Corbel";
Defined this way, fontName is a pointer

> Reference< XSpreadsheet > rSpSheet (rSheet, UNO_QUERY);
>
> Reference< XCell > rCell = rSpSheet->getCellByPosition(x, y);
>
> Reference< XPropertySet > xPropSet(rCell, UNO_QUERY);
>
>  
>
> OUString sstring = OUString(RTL_CONSTASCII_USTRINGPARAM(fontName));

The macro RTL_CONSTASCII_USTRINGPARAM( constAsciiStr ) expands to

constAsciiStr, ((sal_Int32)(sizeof(constAsciiStr)-1)), RTL_TEXTENCODING_ASCII_US

so that

sizeof( pointer ) - 1

is 4 - 1 (in 32 bit arch.) or 8 - 1 (in 64 bit arch.)

> xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontNam
> e")), makeAny(sstring));
>
>  
>
> But when I look into a cacl document, there is wrong value in cell(0,1). I's
> "Cor". But must be "Corbel".

Your OS is 32 bits: (sizeof( pointer ) - 1) is 3, thus "Cor".

 
> Can you help me and show where I'm wrong?

Define the string literal as an array:

const char fontName[] = "Corbel";

or simply avoid all these temporal variables:

xPropSet->setPropertyValue(
OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontName")),
makeAny(OUString(RTL_CONSTASCII_USTRINGPARAM("Corbel"))));



Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
jg
Reply | Threaded
Open this post in threaded view
|

Re: uno api problem

jg
This might also work:

xPropertySet->setPropertyValue(L"CharFontName", makeAny(OUString((const
sal_Unicode *)L"Corbel")));

Or, if the value is not a constant (MFC):

CStringW value;
...
OUString value((const sal_Unicode *)((LPCWSTR)value));
xPropertySet->setPropertyValue(L"CharFontName", Any(value));



jg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: uno api problem

k.misha
I already fixed this problem this way:<неи<неиint nLenOfWideCharStr =<неи            MultiByteToWideChar(<неи            CP_ACP,<неи            MB_PRECOMPOSED,<неи            fontName,<неи            -1,<неи            NULL,<неи            0<неи        );<неи<неи wchar_t *cFontName = (PWSTR)HeapAlloc(GetProcessHeap(), 0, nLenOfWideCharStr * sizeof(WCHAR));<неи<неи MultiByteToWideChar(<неи        CP_ACP,<неи        MB_PRECOMPOSED,<неи        fontName,<неи        -1,<неи        cFontName,<неи        nLenOfWideCharStr<неи    );<неи<неи OUString sstring = cFontName;<неи<неи    rColProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CharFontName")), makeAny(sstring));<неи<неиThanks :)<неи<неи<неи-----Original Message-----<неиFrom: jg [mailto:[hidden email]] <неиSent: Saturday, April 06, 2013 3:15 PM<неиTo: [hidden email]<неиSubject: Re: uno api problem<неи<неиThis might also work:<неи<неиxPropertySet->setPropertyValue(L"CharFontName", makeAny(OUString((const <неиsal_Unicode *)L"Corbel")));<неи<неиOr, if the value is not a constant (MFC):<неи<неиCStringW value;<неи...<неиOUString value((const sal_Unicode *)((LPCWSTR)value));<неиxPropertySet->setPropertyValue(L"CharFontName", Any(value));<неи<неи<неи<неиjg<неи<неи---------------------------------------------------------------------<неиTo unsubscribe, e-mail: [hidden email]<неиFor additional commands, e-mail: [hidden email]<неи<неи

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: uno api problem

Ariel Constenla-Haile-2
On Sun, Apr 07, 2013 at 04:06:19PM +0300, k.misha wrote:
> I already fixed this problem this way:
[...]

not portable at all. You may find useful the C++ UNO binding reference:
http://www.openoffice.org/api/docs/cpp/ref/names/index.html


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment