2012-06-21 194 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

相關問題