This works:
Code:
#include <stdio.h>
#include <windows.h>
int main(void)
{
HKEY hKey;
DWORD dwLen = MAX_PATH;
char szKeyEn[MAX_PATH] = { 0 };
DWORD dwType = 0;
DWORD dwRetVal = 0;
if (ERROR_SUCCESS == (dwRetVal = RegOpenKeyEx(
HKEY_CURRENT_USER,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
0,
KEY_QUERY_VALUE,
&hKey)))
{
if (ERROR_SUCCESS == (dwRetVal = RegQueryValueEx(hKey, "Startup",
NULL, &dwType, (LPBYTE)szKeyEn, &dwLen)))
{
if (dwType == REG_EXPAND_SZ)
{
char szStartupPath[MAX_PATH];
if (0 != ExpandEnvironmentStrings(szKeyEn, szStartupPath, MAX_PATH))
printf ("Value is %s\n", szStartupPath);
else
printf ("Error expanding value: %ld\n", GetLastError());
}
else if (dwType == REG_SZ)
{
printf ("Value is %s\n", szKeyEn);
}
else
{
printf ("Unexpected type returned: %ld\n", dwType);
}
}
else
{
printf ("Error querying value: %ld\n", dwRetVal);
}
RegCloseKey(hKey);
}
else
{
printf ("Error opening key: %ld\n", dwRetVal);
}
return 0;
}