2

I need to pass char* to XPCOM function but that function accepts PRUnichar *. How to convert from char* to PRUnichar * ?

Xinus
  • 29,617
  • 32
  • 119
  • 165

3 Answers3

3

Take a look at nsAutoString.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
2

If you have a UTF-8 string then you can use NS_ConvertUTF8toUTF16 or CopyUTF8toUTF16. If you have some other encoding then you'll need to use nsICharsetConverterManager or some other API to convert to something sane: http://mxr.mozilla.org/mozilla-central/source/intl/uconv/idl/nsICharsetConverterManager.idl

The XPCOM string guide has a good reference on this: https://developer.mozilla.org/En/XPCOM:Strings#Unicode_Conversion_nsCString_vs._nsString

Ted Mielczarek
  • 3,919
  • 26
  • 32
1

In which character set is your char* ?

Neil
  • 54,642
  • 8
  • 60
  • 72