# String and wchar\_t\*

**URL:** <https://forum.juce.com/t/string-and-wchar-t/6308>\
**Category:** General JUCE discussion\
**Created:** [January 29, 2011, 3:11pm UTC](https://forum.juce.com/t/string-and-wchar-t/6308 "2011-01-29T15:11:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OBO](https://avatars.discourse-cdn.com/v4/letter/o/ba8739/32.png) [@OBO](https://forum.juce.com/u/OBO)\
**Post date:** [January 29, 2011, 3:11pm UTC](https://forum.juce.com/t/string-and-wchar-t/6308/1 "2011-01-29T15:11:16Z")

</div>

I my juce app, I get compiles errors whenever i assign a String to a const wchar\_t\*  
I cant avoid wchar\_t entierly and the new string class changes make it incompatible with wchar\_t\*

Is there a good reason for this and whats my preferred route?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 29, 2011, 3:18pm UTC](https://forum.juce.com/t/string-and-wchar-t/6308/2 "2011-01-29T15:18:07Z")

</div>

[quote=“OBO”]I my juce app, I get compiles errors whenever i assign a String to a const wchar\_t\*  
I cant avoid wchar\_t entierly and the new string class changes make it incompatible with wchar\_t\*

Is there a good reason for this and whats my preferred route?[/quote]

wchar\_t implies a UTF-16 encoded string on Windows, and UTF-32 encoded string everywhere else. Jules is in the process of upgrading Juce to support all UTF-encodings, and probably he will make it so that juce\_wchar is consistent for all platforms (likely a UTF-32 code point but its still in development and subject to change).

The question is, what do you really want? If you are on Windows and you want a UTF-16 encoded string, then call String::toUTF16(). If you want a UTF-8 encoded string then call String::toUTF8(), etc… keep in mind these functions are a bit of hack, they enlarge the storage for the String and tack the UTF-encoding on the end. So if you call toUTF16() or toUTF8() twice in a row the String gets bigger and bigger.

What platform are you on and what is your use-case? I’m sure we can figure out the right solution once we know this.

---

<div class="post-metadata">

**Author:** ![OBO](https://avatars.discourse-cdn.com/v4/letter/o/ba8739/32.png) [@OBO](https://forum.juce.com/u/OBO)\
**Post date:** [February 13, 2011, 11:25pm UTC](https://forum.juce.com/t/string-and-wchar-t/6308/3 "2011-02-13T23:25:55Z")

</div>

Vinn, Thanks for reply.

My problem is this:

I made some library using juce but since my customer dont like to link with juce it is wrapped into a generic c dll interface.  
The interface has methods that takes strings and also return strings, and in lack of a better type, wchar\_t is my current choice…

So, i have internally juce strings, but externally wchar\_t pointers. With previous juce version that was no problem, but now the best idea i have is to platform specific conversions (juce::String to utf16 on windows, uft32 on others).

Anybody got good ideas?

In case nothing better comes up, is .toUTF16/32() a correct approach (compatible with wchar)?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 13, 2011, 11:36pm UTC](https://forum.juce.com/t/string-and-wchar-t/6308/4 "2011-02-13T23:36:49Z")

</div>

You can write your own simple conversion class and use it to map the parameters on entry and exit.
