Wchar on Mac / toWideCharPointer()


I have an application where it’s mandatory to use wprintf in a third party library. That’s why I tried to use String::toWideCharPointer() to create the wchar_t *.

That means essentially following code:

wprintf(L"%s", wstring->toWideCharPointer());

On Windows I get as output “DirectX” for e.g. the AudioType. On Mac (10.7.3) the console output is “D”. That sounds to me like the wchar encoding is not UTF-32 like it is standard on Mac OS X. Can I change the encoding? Maybe I can force the internal representation of Juce to something like UTF-32?

kind regards


It outputs a wchar_t string. Perhaps your function is expecting some other kind of string.


Hhm, to eliminate the “library-funtion” in the first place I used wprintf like in the code snippet above :wink:
So , I am quite sure the third party library is not the point because I am not going to use it until I can use
wchar’s from JUCE correctly.

The Juce String is generated by deviceManager.getAvailableDeviceTypes()[index]->getTypeName();

I can track it down to one single line of code:

wprintf(L"%s", deviceManager.getAvailableDeviceTypes()[0]->getTypeName()->toWideCharPointer());

To make it a bit more clear “DirectX” is printed on Windows and on Mac OS X I get “C” like “CoreAudio”.



“%s” tells it to expect a char*, not a wchar_t*


mmpf… sorry my fault. How could I miss that one? It must be %ls … So, it’s not Juce’s fault :slight_smile:

Thanks for your patience.