If you are writing code that will be included in the mozilla source tree, then you need to #include "nsDependentString.h"

-Darin


Darin Fisher wrote:


What header files are you including? That error indicates that the compiler knows nothing of nsDependentString.

More to the point: are you writing code that will be included in the mozilla source tree, or are you writing a mozilla extension / embedding mozilla?

If the latter case, then you should NOT be using nsDependentString. You should be using nsEmbedString instead.

-Darin


Antoine Julien wrote:


According to the Guide to the Mozilla string classes (http://mozilla.org/projects/xpcom/string-guide.html#Appendix_WhatToUse), the nsDependentString should be used when you have a const char* or const PRUnichar* buffer that you need to pass to a function that requires a nsAC?String. (am I wrong to think that?)

My situation is the following: I have a const char* string that I need to pass to a method that requires a nsAString& (that method is nsIDOMCharacterData::InsertData(PRUInt32 offset, const nsAString& arg)). However, when I try, it refuses to compile. Here's the snippet :

/************* BEGIN SNIPPET *********************************/
nsIDOMText* aTextNode ; // already initialized
PRUInt32 anOffset = 1 ;

const char* mbString = "Test string" ; /* the const char* is actually a parameter of the current method */

PRUnichar* wcString = (PRUnichar*)nsMemory::Alloc(strlen(mbString)+1);

mbstowcs(wcString,mbString,strlen(mbString)) ; /* converts the char* to PRUnichar* */

aTextNode->InsertData(anOffset,nsDependentString(wcString)) ;

/************** END SNIPPET ********************************/

When I try this, I get the following error :

error C2440: 'type cast' : cannot convert from 'PRUnichar *' to 'nsDependentString'


What am I doing wrong? I've seen several places in the Mozilla code where the same operation is being done (one of the oh so many can be found at http://lxr.mozilla.org/seamonkey/source/editor/composer/src/nsEditorSpellCheck.cpp#253), I just don't see why their code works and not mine.



Thanks a lot.



A. _______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom



_______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom


_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to