我對Windows開發相當新穎(在Mac方面經驗豐富),並且試圖使用SHGetFolderPath(因爲它與Windows XP兼容)來獲取當前用戶的應用程序數據文件夾的路徑。 。然而,我得到「C」每一次的輸出路徑,無論我通過什麼標誌我都試過:無論如何,SHGetFolderPath都返回「C」?
CSIDL_APPDATA
和
CSIDL_LOCAL_APPDATA
與不CSIDL_FLAG_CREATE標誌。每次都有同樣的結果:「C」。我在這裏做錯了什麼?
#include <windows.h>
#include <shlobj.h> // SHGetFolderPath
#include <stdio.h>
#include <stdlib.h>
//#pragma comment(lib, "shell32.lib")
int main()
{
CHAR path[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path);
if (result != S_OK)
printf("Error: %d\n", result);
else
printf("Path: %s\n" , path);
printf("String length: %d\n", strlen(path));
return 0;
}
的文檔的SHGetFolderPath: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx
這與wchar相關的問題與此處相同:http://stackoverflow.com/questions/8026996/getcurrentdirectory-buffer-doesnt-return-the-right-value – alk