The MSDN page for SHGetSpecialFolderPath says:
SHGetSpecialFolderPath is not supported. Instead, use ShGetFolderPath.
But ShGetFolderPath is deprecated and contains this note:
As of Windows Vista, this function is merely a wrapper for SHGetKnownFolderPath. The CSIDL value is translated to its associated KNOWNFOLDERID and then SHGetKnownFolderPath is called. New applications should use the known folder system rather than the older CSIDL system, which is supported only for backward compatibility.
The correct way to do this is now:
#include "stdafx.h"
#include <windows.h>
#include <KnownFolders.h>
#include <ShlObj.h>
int main()
{
PWSTR path = NULL;
HRESULT result = SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &path);
if (SUCCEEDED(result)) {
wprintf_s(L"Path: %ls\n", path);
}
CoTaskMemFree(path);
return 0;
}