On Tue, Nov 23, 2004 at 09:25:44AM +0100, Petar Popara wrote:
> NS_IMETHODIMP nsMyPlugin::GetMyProp(char * *aMyProp)
> {
> *aMyProp = m_MyProp;
> return NS_OK;
> }
>
> NS_IMETHODIMP nsMyPlugin::SetMyProp(const char * aMyProp)
> {
> //Which function I should use to clone aMyProp here:
> //m_MyProp = nsMemory::Clone(aMyProp);
> m_MyProp = (char*)aMyProp;
> return NS_OK;
> }
Er, actually, your code is wrong. You must clone the memory in the get
method, using nsMemory::Clone or some other nsMemory function.
Otherwise, you will crash if get is called more than once per set.
Which allocator you then use in the set method doesn't matter, since it
is your responsibility to free the string.
I do suggest using string classes, at least for m_MyProp. Try nsCString.
If you use "attribute ACString myProp;" in the IDL, then you also don't
need to deal with allocators in the get/set methods, you can just do
aMyProp.Assign(m_MyProp);
Do note though that neither string nor ACString support non-latin1
characters, and they are really expected to only contain ASCII ones. If
that's an issue for you use AUTF8String/AString/wstring.
-biesi
--
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom