Issues with String on Windows (VS 2013)

I'm trying to make a dynamic library for windows using juce core, but when I create a string the application crashes.

I have thie following code:

String dir("C://Users//SpongeBob//Documents//");

return dir;

But the returned text is the following:


 {text={data=0x05ba2bc8 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþùoý<uË\b\x18:™p\x2" } }    const juce::String &

I access this code using som c# calls, can anybody help me with that?

 

NOTE: On android, iOS and Mac it works without any problem.

And what's the return type of the function that this code is taken from?

Ups, I forgot it, here it is

const String& SystemInfo::getAppDataDir()
{
    String dir("C://Users//SpongeBob//Documents//");
    return dir;
}

It is just a String

Yep, that's what I expected to see, and if you can't see why there's a huge mistake in your code, I think you need to go back re-read some basic C++ tutorials!

lol... I see it :)

I would like to ask you something then... I have a class that is providing system information (like the path, some ids, screen size...) and I have all the info stored in static fields

private:
    static String appName;
    static String appId;    
    static String appVersion;
    ...
    

And we rturn the reference:

const String& SystemInfo::getAppDataDir()
{
    return appDataDir;
}

The thing is that I do not want anybody to be able to modify this values, but I'm not sure if I should return a String reference or a copy. What do you thing?

 

Thanks!!

If it's static, you could return a const String&, otherwise return a String.