Pergunta

I'm trying to parse a SHGetSpecialFolderPath into a string, a System::String^ to be precise.
I'm now using this code:

TCHAR appDataPath;
SHGetSpecialFolderPath(0, appDataPath, CSIDL_APPDATA, false);

I've tried things like this, but it doesn't work either:

LPWSTR appDataPath;
SHGetSpecialFolderPath(0, appDataPath, CSIDL_APPDATA, false);

I just want to get a System::String^ like this:

System::String ^ loc_inst = appDataPath + "\\inst\\info.xml";
Foi útil?

Solução

I don't think C++/CLI can automatically concatenate char arrays and assign them to a string handle. I think you need to instantiate a new System::String object like this:

System::String^ loc_inst = gcnew System::String(appDataPath);
loc_inst.Append("\\inst\\info.xml");

Or you could use a StringBuilder, but if you want to make a new String object I think you've got to use gcnew and a constructor.

Keep in mind that appDataPath is not a String but a char array that you have previously allocated. However, System::String allows you to pass in char arrays in one of its constructors.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top