2012-06-21 197 views
1

我想解析一个SHGetSpecialFolderPath到一个字符串,一个System::String^准确。
我现在使用此代码:SHGetSpecialFolderPath到系统::字符串^

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

我已经试过这样的事情,但它不工作之一:

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

我只是想获得一个System::String^这样的:

System::String^loc_inst = appDataPath + "\\inst\\info.xml"; 
+2

改为使用Environment :: GetFolderPath()。 –

回答

1

我不认为C++/CLI可以自动连接字符数组并将它们分配给字符串句柄。我认为你需要实例化一个新的System::String对象是这样的:

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

或者你可以使用一个StringBuilder,但如果你想使一个新的String对象,我认为你必须使用gcnew和构造函数。

请记住,appDataPath不是String,而是您先前分配的char数组。但是,System::String允许您在其构造函数之一中传入char数组。

+0

啊,谢谢,现在编码: StringBuilder^build_str = gcnew StringBuilder(“”,MAX_PATH); \t \t \t 对(INT I = 0;我追加(gcnew阵列 {appDataPath [I]}); } System :: String^loc_inst = build_str-> ToString(); – Jers

相关问题