[omniORB] How to assign a wchar_t array?
baileyk@schneider.com
baileyk@schneider.com
Thu Dec 5 14:32:01 2002
Translating what I would normally do for narrow strings:
//sourcecode
void Echo_i::echoString(Example::StringList_out idList)
{
int length = 0;
//getIDList returned "return((wchar_t**)aArray);"
// with the length "length"
wchar_t** List=getIDList(&length);
Example::StringList_var tmpList( new Example::StringList(length) );
tmpList->length(length);
for(i=0;i<length;i++)
{
tmpList[i] = CORBA::wstring_dup(List[i]);
wprintf(L"myList: %s\n",List[i]);
}
CoTaskMemFree(List);
idList = tmpList._retn();
}
things to know:
** Both the _var and _out types for sequences have an operator[] method
which does the right thing. Theres no need to use an expression like :
(*idList)[i]
when this will do the same thing :
idList[i]
** Technically, you don't need CORBA::[w]string_dup() if the pointer is to
a pointer to const char/CORBA::WChar. I use it always just to be sure
because some compilers don't implicitly invoke it when they should. So any
string that is being placed inside an IDL struct, array or out param should
be properly dup'd. The case here definitely needs it since List is
wchar_t** and not wchar_t const**
** I'm not sure whether the ORB is guaranteed to be responsible for the
cleanup of an _out parameter if the method throws an exception. I use _var
types throughout and then copy them to the _out params using the _retn()
method to transfer ownership from _var to _out object.
just a guess:
** I'm no Windows COM programmer, but I would guess that CoTaskMemFree
doesn't know that List is a pointer to pointers. If each wchar_t* in the
List is also dynamically allocated, which seems likely, then shouldn't
there be a line inside the loop which does "CoTaskMemFree( List[i] )" or
similar?
Kendall
Slava Garelin
<garelin@ukr.net> To: "Uli Syber" <uli.syber@schraml.de>,
Sent by: omniorb-list@omniorb-support.com
omniorb-list-admin@omniorb-s cc:
upport.com Fax to:
Subject: Re: [omniORB] How to assign a wchar_t array?
12/05/2002 03:03 AM
5 Декабрь 2002 09:22, Uli Syber написал:
Hi, Uli.
IMHO like so:
> //sourcecode
> void Echo_i::echoString(Example::StringList_out idList)
> {
> //int i=0;
> int length;
>
>
> wchar_t** List=getIDList(&length); //getIDList
returned
> "return((wchar_t**)aArray);" with the length "length"
>
idList = new Example::StringList(length);
idList->length(length);
> for(i=0;i<length;i++)
> {
>
> //*(idList+i)=(wchar_t)*(List+i);
(*idList)[i] =List[i];
>
> //idList[i]=(wchar_t)*(List+i); didn?t work
>
> wprintf(L"myList: %s\n",*(List+i));
> }
> CoTaskMemFree(List);
>
> }
>
--
Slava Garelin
_______________________________________________
omniORB-list mailing list
omniORB-list@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list