You could simply query the registry value.....
Put this function in your code and use it when you want the path of the desktop as a string
Code:
#include <windows.h>
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
char* GetDesktopPath(void){
ULONG ulDataType;
HKEY hKey;
DWORD dwToRead = 100;
static char strPath[100];
char strKey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
RegOpenKeyEx(HKEY_CURRENT_USER,strKey,
0,KEY_READ,&hKey);
RegQueryValueEx(hKey,"Desktop",NULL,
&ulDataType,(LPBYTE)strPath,&dwToRead);
strPath[dwToRead] = '\0';
RegCloseKey(hKey);
return strPath;
}
int main()
{
cout << GetDesktopPath() << endl;
return 0;
}
You need to include the windows.h in your application......
I tested it on Win2000 & Win98 and it worked fine......have a try