String and wchar_t*


#1

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?


#2

[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.


#3

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)?


#4

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